解题思路:
虽然没必要用这么复杂的方法,
但就当是温习一下快速排序的算法吧
注意事项:
参考代码:
#include <stdio.h> int partition(int arr[], int low, int high) { int key; key = arr[low]; while (low < high) { while (low < high && arr[high] >= key) high--; if (low < high) arr[low++] = arr[high]; while (low < high && arr[low] <= key) low++; if (low < high) arr[high--] = arr[low]; } arr[low] = key; return low; } void quick_sort(int arr[], int start, int end) { int k; if (start < end) { k = partition(arr, start, end); quick_sort(arr, start, k - 1); quick_sort(arr, k + 1, end); }return; } int main() { int a[10], t; for (int i = 0; i < 9; i++) scanf("%d", &a[i]); scanf("%d", &a[9]); quick_sort(a, 0, 9); for (int i = 0; i < 10; i++) printf("%d\n",a[i]); return 0; }
0.0分
0 人评分