Simple Bubble SortingAlgorithm,CodeAs follows:
// Bubble Sorting (traversal starts from the starting position of the array, with a large base: sinking a large number)
Private Static Void Bubblesortfunction ( Int [] Array)
{
Try
{
Int Length = Array. length;
Int Temp;
Bool Hasexchangeaction; // Record whether two adjacent numbers in this large loop have been exchanged (if not, the array is already ordered)
For ( Int I = 0 ; I < Length - 1 ; I ++ ) // Array has N number, then the use of N-1 large loop can be completed
{
Hasexchangeaction = False ; // Each large loop assumes that the array is ordered.
For ( Int J = 0 ; J < Length - I - 1 ; J ++ ) // Traverse from the array subscript 0, (length-I-1 is to partition the large number already exclusive)
{
If (Array [J] > Array [J + 1 ]) // Compare two adjacent numbers. If the preceding number is greater than the following number, swap the adjacent two numbers.
{
Temp = Array [J];
Array [J] = Array [J + 1 ];
Array [J + 1 ] = Temp;
Hasexchangeaction = True ; // Swapping
}
}
If ( ! Hasexchangeaction) // If there is no swapping, the array is already ordered and the loop jumps out.
{
Break ;
}
}
}
Catch (Exception ex)
{}
}
.....