@ -59,4 +59,20 @@ void quickSort(int arr[], int low, int high) {
}
//直接选择排序
void selectSort(int arr[], int n) {
for (int i = 0; i < n - 1; i++) {
int min = i;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[min]) {
min = j;
if (min != i) {
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
@ -14,7 +14,7 @@ int main() {
int n = sizeof(arr) / sizeof(arr[0]);
printf("%d\n",n);
quickSort(arr,0,4);
selectSort(arr,5);
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);