Binary Lookup Sort

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.