选择排序
void select_sort(int arr[], int length) {
for (int i = 0; i < length - 1; i++) {
int min_in = i;
for (int j = i + 1; j < length; j++) {
if (arr[j] < arr[min_in]) {
min_in = j;
}
}
swap(arr[i], arr[min_in]);
}
}
插入排序
void insert_sort(int arr[], int length) {
for (int i = 1; i < length; i++) {
int temp = arr[i];
int j;
for (j = i; arr[j - 1] > temp && j > 0; j--) {
arr[j] = arr[j - 1];
}
arr[j] = temp;
}
}
冒泡排序
void bubbling_sort(int arr[], int length) {
int exchange = length;
while (exchange != 0) {
int END = exchange;
exchange = 0;
for (int i = 1; i < END; i++) {
if (arr[i] < arr[i - 1]) {
swap(arr[i], arr[i - 1]);
exchange = i;
}
}
}
}