其他分享
首页 > 其他分享> > 奇数单增序列(快速排序)

奇数单增序列(快速排序)

作者:互联网

 1 #include <iostream>
 2 using namespace std;
 3 int a[500];
 4 
 5 void qsort(int l, int r) {
 6     int i, j, mid, p;
 7     i = l; j = r;
 8     mid = a[(l+r)/2];
 9     do {
10         while (a[i]<mid) i++;
11         while (a[j]>mid) j--;
12         if (i<=j) {
13             p = a[i]; a[i] = a[j]; a[j] = p;
14             i++; j--;
15         }
16     } while (i<=j);
17     if (l<j) qsort(l, j);
18     if (i<r) qsort(i, r);
19 }
20 
21 int main() {
22     int n, t, k=0;
23     cin >> n;
24     for (int i=0; i<n; i++) {
25         cin >> t;
26         if (t%2==1) a[k++] = t;
27     }
28     qsort(0, k-1);
29     for (int i=0; i<k-1; i++)
30         cout << a[i] << ",";
31     cout << a[k-1] << endl;
32     return 0;
33 }

 

标签:24,单增,奇数,int,namespace,qsort,mid,29,排序
来源: https://www.cnblogs.com/vergica/p/15704441.html