Page 568 - ComputerScience_Class_11
P. 568

Program 4      Design a class Bubble_Binary sorts a given array using the Bubble Sort technique and search
                               an accepted element using the binary search technique. A main class is to be created to give
                               details of the constructors and the member methods.
                               Data Members
                               int n                           :  To store the array size
                               int sno                         :   To store the number to be searched
                               int ar[ ]                       :   To store array elements
                               Member Methods
                               Bubble_binary( )                :  To initialise all the data members to 0
                               void accept( )                  :   To store the size of the array and the elements of  the
                                                                 array
                               void Bubble_Sort( )             :    To sort the array using the bubble sort technique and
                                                                 display it
                               void binary_search( )           :   To accept the user-given number and search it using
                                                                 the binary search technique

                 1       import java.util.*;
                 2       class Bubble_Binary

                 3       {
                 4           int n,sno;

                 5           int ar[];
                 6           Bubble_Binary()

                 7           {
                 8               n=sno=0;

                 9           }

                10
                11           void accept()
                12           {

                13               Scanner sc=new Scanner(System.in);

                14               System.out.println("ENTER THE SIZE OF THE ARRAY");
                15               n=sc.nextInt();

                16               ar=new int[n];
                17               System.out.println("ENTER THE ARRAY ELEMENTS");

                18               for(int i=0;i<n;i++)  //accepting values from user
                19                   ar[i]=sc.nextInt();

                20           }
                21

                22           void Bubble_Sort()






                  566  Touchpad Computer Science (Ver. 3.0)-XI
   563   564   565   566   567   568   569   570   571   572   573