------------------Learning bubble sorting algorithm come with me----------------

Source: Internet
Author: User

Learn this overall sentence: The outer end needs to reduce one, the inner end minus I minus one,

The Da Lei algorithm makes comparisons, comparing J and J+1,

If you do not want to report abnormal, must not have an equal sign.


Bubble sort
public static void Main (string[] args) {
int num []={18,200,27,198,190,175};
The array arrangement before sorting.
for (int i = 0; i < num.length; i++) {
System.out.println (Num[i]);
}
Compare the number of neighbors, who are big in the back,
for (int i = 0; i < num.length-1; i++) {
for (int j = 0; J < Num.length-i-1; J + +) {

Swap position (Daleitai)
if (Num[j]>num[j+1]) {
int TEMP=NUM[J];
NUM[J]=NUM[J+1];
Num[j+1]=temp;
}

}
}
for (int i = 0; i < num.length; i++) {
System.out.println ("Sorted array of permutations:" +num[i]);
}

}

}

------------------Learning bubble sorting algorithm come with me----------------

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.