C # positive solution of Bubble Sorting!

Source: Internet
Author: User
Today, a friend asked me an example of Bubble sorting. As I was busy, I told him that there were many examples on the Internet. I asked him to search for them. Then he sent me another message, I hate it.
Isn't that a false future?
Let's take a look at the online Bubble Sorting example: 1 Public   Void Sort ( Int [] List)
2 {
3 While (J < List. length)
4 {
5 For (I = 0 ; I < List. Length - 1 ; I ++ )
6 {
7 If (List [I] > List [I + 1 ])
8 {
9 Temp = List [I];
10 List [I] = List [I + 1 ];
11 List [I + 1 ] = Temp;
12 }
13 }
14 J ++ ;
15 }
16

In this example, I would like to ask, why is this J used? I read it online, and there are many examples like this.
It's really harmless!
You can only write one.
The following is a positive solution. Simple Example: Protected   Int [] Bubbleup ( Int [] Array)
{
For ( Int I =   0 ; I < Array. length; I ++ )
{
For ( Int J = I + 1 ; J < Array. length; j ++ )
{
If (Array [I] > array [J])
{< br> int temp = array [I];
array [I] = array [J];
array [J] = temp;
}
}
}
Return Array;
}

Hope to help friends who do not know Bubble Sorting!
Http://www.cnblogs.com/emanlee/archive/2008/04/28/1174071.html

Related Article

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.