*? bubble sort
*? Compare adjacent elements. If the first one is bigger than the second one, change them. ?
*? Do the same work for each pair of adjacent elements, from the first pair to the last pair. At this point, the last element should be the largest number. ?
*? Repeat the above steps for all elements except the last one.
*? Repeat the above steps for fewer and fewer elements at a time until there are no number pairs to compare. ?
*? @param? Numbers? An array of integers that need sorting.
*/
Public? Static electricity Invalid? bubbleSort(int[]? Numbers)
{
int? Temporary workers? =? 0;
int? Size? =? Numbers. Length;
for(int? Me? =? 0? ; ? Me? & lt? size- 1; ? Me? ++)
{
for(int? j? =? 0? ; j? & lt? size- 1-i? ; ? j++)
{
if(numbers[j]? & gt? numbers[j+ 1])? //Exchange the position of two digits
{
Temporary workers? =? Number [j];
Number [j]? =? Number [j+1];
Number [j+ 1]? =? Temperature;
}
}
}
}
The basic idea of quick sorting is:
The records to be sorted are divided into two independent parts through one-time sorting, in which the keywords of one part of the records are smaller than the other part, and then the two parts are sorted separately until the whole sequence is orderly.
/**
*? After sorting in the numbers array, find out the position of the central axis (the lowest bit is low by default).
*?
*? @param? Numbers? Array with lookup
*? @param? Low starting position
*? @param? Tall? End position
*? @ Return? The position of the central axis
*/
Public? Static electricity int? getMiddle(int[]? Numbers? int? Low, int? High)
{
int? Temporary workers? =? Number [low]; ? //The first of the array serves as the central axis.
And (low? & lt? High)
{
And (low? & lt? Tall? & amp& amp? Number [high]? & gt? Temperature)
{
High-;
}
Number [low]? =? Number [high]; //Records smaller than the central axis move to the lower end.
And (low? & lt? Tall? & amp& amp? Number [low]? & lt? Temperature)
{
Low++;
}
Number [high]? =? Number [low]? ; ? //Records larger than the central axis are moved to the high end.
}
Number [low]? =? Temporary workers? ; ? //axis records to the end
Return? Low? ; ? //? Return to the position of the central axis
}
Recursive divide-and-conquer sorting algorithm;
/**
*?
*? @param? Numbers? Sorted array
*? @param? Low? Starting position
*? @param? Tall? End position
*/
Public? Static electricity Invalid? quickSort(int[]? Numbers, int? Low, int? High)
{
If (low? & lt? High)
{
int? In the middle =? GetMiddle (number, low, high); ? //Divide the number array into two.
Quick sort (number, low,? Middle-1); //Recursively sort the low field table.
Quick sort (number, middle+1,? High); ? //Recursively sort the high field table.
}
}