Page 495 - Cs_withBlue_J_C11_Flipbook
P. 495

46              int min=0, max=(n-1),mid=0,p=-1;
                   47              while(min<=max&&p==-1)           //searching the user given number

                   48              {
                   49                  mid=(min+max)/2;

                   50                  if(ar[mid]==sno)
                   51                      p=mid;

                   52                  else if(ar[mid]>sno)
                   53                      max=mid-1;
                   54                  else

                   55                      min=mid+1;

                   56              }
                   57              if(p!=-1)
                   58                  System.out.println("YES. THE POSITION IS "+(p+1));

                   59              else
                   60                  System.out.println("NOT FOUND");

                   61          }
                   62

                   63          public static void main()
                   64          {

                   65              Bubble_Binary ob=new Bubble_Binary();
                   66              ob.accept();

                   67              ob.Bubble_Sort();
                   68              ob.binary_search();

                   69          }                                    //end of main
                   70      }


                 The output of the preceding program is as follows:
                 ENTER THE SIZE OF THE ARRAY
                 5
                 ENTER THE ARRAY ELEMENTS
                 1
                 6
                 5
                 2
                 4
                 THE SORTED ARRAY IS:-
                 1
                 2
                 4



                                                                                                                       493
                                                                                                   Internal Assessment  493
   490   491   492   493   494   495   496   497   498   499   500