Java Implementation Direct Insert Lookup

Source: Internet
Author: User

1 ImportJava.util.Scanner;2 3 /*algorithm idea: Each trip will be a sort of element as a keyword, according to the size of the keyword value inserted into the order of the sequence of the appropriate position, until the insertion is complete,*/4 /*Average Time complexity O (n^2), Space complexity O (1)*/5 /*Features: Insert sort All is the last trip to complete without any record reaching its final position*/6 7  Public classZhijiecharusort {8      Public Static voidMain (String strg[]) {9Scanner cin =NewScanner (system.in);TenString str =cin.nextline (); OneString st[] = Str.split (""); A         intc[]=New int[st.length]; -          for(inti=0;i<st.length;i++){ -c[i]=Integer.parseint (St[i]); the         } - Insertsort (c); -          for(inti=0;i<st.length;i++){ - System.out.print (C[i]); +System.out.print (""); -         } + cin.close (); A     } at      Public Static voidInsertsort (intr[]) { -         inttemp; -         intJ; -          for(inti=1;i<r.length;i++){ -temp=R[i]; -J=i-1; in              while(j>=0&&temp<R[j]) { -r[j+1]=R[j]; toj--; +             } -r[j+1]=temp; the         }         *     } $}

Java Implementation Direct Insert Lookup

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.