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