Bubble Sort
The simplest sorting method is the Bubble sorting method. The basic idea of this method is to regard the elements to be sorted as vertical "Bubbles", and the smaller elements are relatively light, so as to move up and down. In the Bubble sorting algorithm, we need to process the "bubble" sequence several times. The so-called one-time processing is to check the sequence from the bottom up, and always pay attention to whether the order of two adjacent elements is correct. If the order of two adjacent elements is incorrect, that is, the "light" elements are located below, and their positions are exchanged. Obviously, after processing it again, the "lightest" element floated to the highest position; after processing it twice, the "minor" element floated to the lower position. During the second processing, you do not have to check because the element at the highest position is already the lightest element. In general, the I-th processing does not have to check the elements above the I-th high position, because they are sorted correctly after the processing of the previous I-1 times. This algorithm can be implemented as follows.
The algorithm is as follows:
/**
* Bubble Sorting
* @ Paramsrc: array to be sorted
*/
Void doBubbleSort (int [] src)
{
Int len = src. length;
For (int I = 0; I <len; I)
{
For (int j = I 1; j <len; j)
{
Int temp;
If (src [I]> src [j])
{
Temp = src [j];
Src [j] = src [I];
Src [I] = temp;
}
}
PrintResult (I, src );
}
}