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