Sort _ Simple Sort _ Select sort

Source: Internet
Author: User

Select Sort is a three record value, where one record value marks the first value of the array to be compared, and the minimum value after the transformation. Of these, two record values record the two objects that need to be compared, and record the location of the temporary minimum and record another data that has not yet been compared.

 Public classArraysel {Private Longa[]; Private intNelems;  PublicArraysel (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 voidSelectionsort () {intout,in,min;  for(out=0;out<nelems;out++) {min=out;//each cycle, out and the position of Min are the same//The start of another object that needs to be compared is the second one, either out+1 or min+1             for(in=out+1;in<nelems;in++) {                if(a[in]<a[min]) min=In ; }            //Once the comparison loop is complete, the minimum value of the outer loop is foundswap (out, min); }    }    Private voidSwapintOneintBoth ) {        Longtemp=A[one]; A[one]=A[two]; A[two]=temp; }}
 Public classTest { Public Static voidMain (string[] args) {intmaxsize=100; Arraysel Arraybub=NewArraysel (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.selectionsort ();    Arraybub.display (); }}

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