Sort _ Simple Sort _ Insert Sort

Source: Internet
Author: User

The insert sort has three record values, one of which records the value that is taken out, and the value to be inserted, starting at the second position. The other two initial positions are the same, starting with the second value recording. This is characterized by an orderly array of current assumptions before each comparison.

 Public classArrayins {Private Longa[]; Private intNelems;  PublicArrayins (intmaxSize) {a=New Long[MaxSize]; Nelems=0; }    //Insert     Public voidInsertLongvalue) {A[nelems++]=value; }    //Show     Public voiddisplay () { for(intj=0;j<nelems;j++) System.out.print (A[j]+" ");    System.out.println (); }    //Sort     Public voidInsertionsort () {intOut,in;  for(out=1;out<nelems;out++) {            Longtemp=A[out]; Inch=Out ;  while(in>0&&a[in-1]>=temp) {A[in]=a[in-1]; Inch--; } A[in]=temp; }    }}
 Public classTest { Public Static voidMain (string[] args) {intmaxsize=100; Arrayins Arraybub=NewArrayins (maxSize); Arraybub.insert (77); Arraybub.insert (99); Arraybub.insert (44); Arraybub.insert (55); Arraybub.insert (22); Arraybub.insert (88); Arraybub.insert (11); Arraybub.insert (0); Arraybub.insert (66); Arraybub.insert (33);        Arraybub.display ();        Arraybub.insertionsort ();    Arraybub.display (); }}

Sort _ Simple Sort _ 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.