Posts

Showing posts from May, 2021

new

 App.js import   react , { useEffect ,  useState } from   "react" ; import   './App.css' ; import   Header   from   "./components/Header" ; import   Recipes   from   "./components/Recipes" ; import   Axios   from   "axios" ; function   App () {    const  [ search ,  setSearch ] =  useState ( "Icecream" );    const  [ recipes , setRecipes ] =  useState ([]);    useEffect (() => {       getRecipe ();   },[]);       const   getRecipe  =  async () => {      const   res  =  await   Axios . get ( `https://api.edamam.com/search?q=${ search }&app_id=${ APP_ID }&app_key=${ APP_KEY }&from=0&to=3&calories=591-722&health=alcohol-free` )      setRecipes ( res . data . hits )   }       const   APP_ID  =  "09fd6cf9" ;    const   APP_KEY  =  "5645169c14b6b1216a543e0cfbd04e37" ;        const   onInputChange  =  e   => {             setSearch ( e . target . value )   }    const   onSearch  = ()

sorted Array

Image
 // Java implementation of QuickSort import java.io.*; class GFG{ // A utility function to swap two elements static void swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } /* This function takes last element as pivot, places the pivot element at its correct position in sorted array, and places all smaller (smaller than pivot) to left of pivot and all greater elements to right of pivot */ static int partition(int[] arr, int low, int high) { // pivot int pivot = arr[high]; // Index of smaller element and // indicates the right position // of pivot found so far int i = (low - 1); for(int j = low; j <= high - 1; j++) { // If current element is smaller // than the pivot if (arr[j] < pivot) { // Increment index of // smaller element i++; swap(arr, i, j); } } swap(arr, i + 1, high); return (i + 1); } /* The main function that implements QuickSort arr[] --> Array to be sorted,

Insertion Sort

Image
  // Java program for implementation of Insertion Sort class InsertionSort { /*Function to sort array using insertion sort*/ void sort(int arr[]) { int n = arr.length; for (int i = 1; i < n; ++i) { int key = arr[i]; int j = i - 1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = key; } } /* A utility function to print array of size n*/ static void printArray(int arr[]) { int n = arr.length; for (int i = 0; i < n; ++i) System.out.print(arr[i] + " "); System.out.println(); } // Driver method public static void main(String args[]) { int arr[] = { 12, 11, 13, 5, 6 }; InsertionSort ob = new InsertionSort(); ob.sort(arr); printArray(arr); } } /* This code is contributed by Rajat Mishra. */

Bubble Shot 2 Selection Sort

 // Java program for implementation of Selection Sort class SelectionSort { void sort(int arr[]) { int n = arr.length; // One by one move boundary of unsorted subarray for (int i = 0; i < n-1; i++) { // Find the minimum element in unsorted array int min_idx = i; for (int j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element with the first // element int temp = arr[min_idx]; arr[min_idx] = arr[i]; arr[i] = temp; } } // Prints the array void printArray(int arr[]) { int n = arr.length; for (int i=0; i<n; ++i) System.out.print(arr[i]+" "); System.out.println(); } // Driver code to test above public static void main(String args[]) { SelectionSort ob = new SelectionSort(); int arr[] = {64,25,12,22,11}; ob.sort(arr); System.out.println("Sorted array"); ob.printArray(arr); } } /* This code is contributed by Rajat Mi

bubble short Q1

  Bubble short assening order  5 9 8 -2 1 1st titration 4 comparison  2nd itteretion 3 comparison and so on  comparison = n-i; public   class  BubbleSortExample {        static   void  bubbleSort( int [] arr) {            int  n = arr.length;            int  temp =  0 ;             for ( int  i= 0 ; i < n; i++){                     for ( int  j= 1 ; j < (n-i); j++){                              if (arr[j- 1 ] > arr[j]){                                     //swap elements                                     temp = arr[j- 1 ];                                    arr[j- 1 ] = arr[j];                                    arr[j] = temp;                            }                                               }            }          }        public   static   void  main(String[] args) {                    int  arr[] ={ 3 , 60 , 35 , 2 , 45 , 320 , 5 };                                     System.out.println( "Array Before Bubble Sort" );                    for ( int  i= 0 ; 

calculate the character in string

 public class HelloWorld{      public static void main(String []args){             String string1 = "Hello World";                       int count;                      char string[] = string1.toCharArray();                      for(int i = 0; i <string.length; i++) {               count = 1;               for(int j = i+1; j <string.length; j++) {                   if(string[i] == string[j] && string[i] != ' ') {                       count++;                       string[j] = '0';                   }               }               if(count > 1 && string[i] !='0') {                  System.out.println(string[i]+":-"+count);               }else if (string[i]!='0'&& string[i]!=' '){                 System.out.println(string[i]+":-"+count);             }         }      } }

web scriping in javascript

 npm init -y     type this in terminal npm install request npm js request it should contain a function with a request URL and one callback function  with the help of cheerio we can manipulate the data  const   request   =   require ( ' request ' ) ; request ( ' http://www.google.com ' ,   function   ( error ,   response ,   body )   {    console . error ( ' error: ' ,  error ) ;   //  Print the error if one occurred    console . log ( ' statusCode: ' ,  response  &&   response . statusCode ) ;   //  Print the response status code if a response was received    console . log ( ' body: ' ,  body ) ;   //  Print the HTML for the Google homepage. } ) ; ///////////////////////// // const request = require('request'); // const requre = require("cheerio"); // const fs = require("fs"); // request("https://www.espncricinfo.com/series/ipl-2021-1249214/punjab-kings-vs-delhi-capitals-29th-match-1254086/ball-by-ball-com

youtube

 https://support.google.com/youtube/answer/6390658 click