Sort _ Simple Sort _ bubble sort

Source: Internet
Author: User

The bubbling sort has three record values, two of which point to two objects that need to be compared, one pointing to the end value of the numeric value that needs to be sorted.
In,in+1,out

 Public classArraybub {Private Longa[]; Private intNelems;  PublicArraybub (intmax) {a=New Long[Max]; Nelems=0; }     Public voidInsertLongvalue) {A[nelems]=value; Nelems++; }     Public voiddisplay () { for(intj=0;j<nelems;j++) {System.out.print (A[j]+" ");    } System.out.println (); }    //How to bubble sort     Public voidBubblesort () {intOut,in;//The out record needs to sort the end value of the array         for(out=nelems-1;out>1;out--) {            //Compare the size of two objects (in and in+1)             for(in=0;in<out;in++) {                if(a[in]>a[in+1]) Swap (in, in+1); }        }    }    //Exchange values for two objects    Private voidSwapintOneintBoth ) {        Longtemp=A[one]; A[one]=A[two]; A[two]=temp; }                        }
 Public classTest { Public Static voidMain (string[] args) {intmaxsize=100; Arraybub Arraybub=NewArraybub (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.bubblesort ();    Arraybub.display (); }}

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