Bubble Sorting (Java version)

Source: Internet
Author: User

Bubble Sorting:

Class arraybub {
Private long [];
Private int nelems;
Public arraybub (INT num ){
A = new long [num];
Nelems = 0;
}
Public void insert (long item ){
A [nelems] = item;
Nelems ++;
}
Public long getelem (INT index ){
Return a [Index];
}
Public void setelem (INT index, long value ){

}
Public void bubsort (){
Int outer;
Int inner;
Long temp;
For (outer = nElems-1; outer> 1; outer --){
For (inner = 0; Inner <outer; Inner ++ ){
If (A [inner]> A [outer]) {
Temp = A [inner];
A [inner] = A [outer];
A [outer] = temp;
}
}
}
}
Public void showitem (){
For (INT I = 0; I <nelems; I ++ ){
System. Out. println ("A [" + I + "] =" + A [I]);
}
}
 
}
Public class bubblesort {
Public static void main (string [] ARGs ){
Arraybub AB = new arraybub (10 );
AB. insert (23 );
AB. insert (144 );
AB. insert (56 );
System. Out. println ("Before sorting ");
AB. showitem ();
AB. bubsort ();
System. Out. println ("sorted ");
AB. showitem ();
}
}

It is very simple, but I still write it myself. The end of the paper is shallow. To know this, you must be polite.

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.