Common sorting algorithm
One, bubble sort
public int[] bubbleSort(int[] param) {
int length = param.length;
for (int i = 0; i < length - 1; i++) {
for (int j = 0; j < length - 1 - i; j++) {
if (param[j] > param[j + 1]) {
int temp = param[j + 1];
param[j + 1] = param[j];
param[j] = temp;
}
}
}
return param;
}
Two, quick sort
public int[] quickSort(int[] param, int left, int right) {
if (left < right) {
int index = getIndex(param, left, right);
quickSort(param, left, index - 1);
quickSort(param, index + 1, right);
}
}
public int getIndex(int[] param, int left, int right) {
int temp = param[left];
while (left < right) {
while (left < right && param[right] > temp)
right--;
param[left] = param[right];
while (left < right && param[left] > temp)
left++;
param[right] = param[left];
}
param[low] = temp;
return low;
}
The code is written directly on the web page, there may be minor problems, please correct me.