Java implementation Binary (dichotomy) Insert sort

Source: Internet
Author: User

1 /*binary Insert Find idea: Each trip with a sorted element as a keyword inserted into the appropriate position of the part sequence already arranged, find the appropriate location method with binary lookup method2 * Suitable for recording a large number of scenes3 * Save time when looking for insertion position4 * It is the same as the direct insert lookup in recording the number of moves, so the time complexity is still O (n^2)5 * Spatial complexity of the same as O (1)*/6 7 ImportJava.util.Scanner;8 9  Public classZhebancharusort {Ten  One      Public Static voidMain (String args[]) { AScanner cin =NewScanner (system.in); -String str =cin.nextline (); -String st[] = Str.split (""); the         intNum[] =New int[st.length]; -          for(inti=0;i<st.length;i++){ -num[i]=Integer.parseint (St[i]); -         } + sort (num); -          for(intj=0;j<st.length;j++){ + System.out.print (Num[j]); ASystem.out.print (""); at         } - cin.close (); -     } -      Public Static voidSortintr[]) { -          for(inti=1;i<r.length;i++){ -             if(r[i]<r[i-1]){ in                 intLow=0; -                 intHigh=i-1; to                 inttemp =R[i]; +                  while(low<=High ) { -                     intMID = (int) ((Low+high)/2); the                     if(r[mid]<temp) { *Low=mid+1; $}Else{Panax NotoginsengHigh=mid-1; -                     } the                 } +                  for(intj=i;j>low;j--){ AR[j]=r[j-1]; the                 } +r[low]=temp; -             } $         } $     } -}

Java implementation Binary (dichotomy) Insert 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.