1 #include <stdio.h>
2
3 void sort(int sz[], int low, int high)
4 {
5 int p = sz[low]; // 模仿快速排序,时间复杂度为o(n), 空间复杂度o(1)
6 while (low < high)
7 {
8 while (low < high && (sz[high] % 2 == 0))
9 high--;
10 sz[low] = sz[high];
11 while (low < high && (sz[low] % 2 != 0))
12 low++;
13 sz[high] = sz[low];
14 }
15 sz[low] = p;
16 }
17
18 int main()
19 {
20 int sz[] = {18, 9, 71, 72, 99, 90, 64, 3, 22, 55, 10, 11};
21 sort(sz, 0, 11);
22 for (int i = 0; i < 12; i++)
23 printf("%d ", sz[i]);
24 return 0;
25 }