static final int n=15;static void QuickSort (int[] arr,int left,int right)//fast sort algorithm {int f,t;int rtemp,ltemp; Ltemp=left; Rtemp=right; f=arr[(left+right)/2];//determines the cutoff value while (ltemp<rtemp) {while (arr[ltemp]<f) ++ltemp; while (arr[rtemp]>f)--rtemp; if (ltemp<=rtemp) {//bubble displace t=arr[ltemp]; ARR[LTEMP]=ARR[RTEMP]; Arr[rtemp]=t;--rtemp; ++ltemp;} } if (ltemp==rtemp) ltemp++; if (left<rtemp) QuickSort (arr,left,ltemp-1);//Recursive call if (ltemp<right) QuickSort (arr,rtemp+1,right);//Recursive Call} static int searchfun (int a[],int n,int x) {//binary find int mid,low,high;low=0;high=n-1; while (Low<=high) {mid= (Low+high)/2;if (a[mid]==x) return mid;//Find the Else if (a[mid]>x) high=mid-1; elselow=mid+1; }return-1;//not found}public static void main (string[] args) {int[] shuzu=new int[n];int x,n,i;for (i=0;i<n;i++) {shuzu[i]= (int) (100+math.random () * (100+1)); /Generate array}system.out.print ("BinaryFind the algorithm demo! \ n "); System.out.print ("Pre-order data series: \ n"); for (i=0;i<n;i++) {System.out.print ("" +shuzu[i]);//Output sequence}system.out.print ("\ n"); QuickSort (shuzu,0,n-1);//Sort System.out.print ("sorted data series: \ n"); for (i=0;i<n;i++) {System.out.print ("" +shuzu[i]);//Output sequence}system.out.print ("\ n"); System.out.print ("Enter the number to find:"); Scanner input=new Scanner (system.in); X=input.nextint ();//Enter the number N=searchfun (shuzu,n,x) to find,//find if (n<0)//Output Find results System.out.println ("No Data Found:" +x); else System.out.println ("Data:" +x+ "is located at the" + (n+1) + "element of the array.) ");}
Binary Lookup Sort