1 #include
2
3 using namespace std;
4
5 int Partition(int *l,int low,int high)
6 {
7 int temp = l[low];
8 int pt = l[low];
9
10 while(low < high)
11 {
12 while(low < high && l[high] >= pt)
13 --high;
14 l[low] = l[high];
15 while(low < high && l[low] <= pt)
16 ++low;
17 l[low] = temp;
18 }
19 l[low] = temp;
20 return low;
21 }
22
23 void Qsort(int *l,int low,int high)
24 {
25 if(low < high)
26 {
27 int pl = Partition(l,low,high);
28 Qsort(l,low,pl - 1);
29 Qsort(l,pl + 1,high);
30 }
31 }
32
33 int main(void)
34 {
35 int narry[100],addr[100]; /* 定义数组*/
36 int sum = 1,t; /* sum为数组的下标 */
37
38 cout << "Input number:"<< endl; /* 接收输入的数,为-1时将不再输出*/
39 cin >> t;
40
41 while(t != -1)
42 {
43 narry[sum] = t; /*该数组下标从1开始 */
44 addr[sum - 1] = t; /*该数组下标从0开始 */
45 sum++;
46 cin >> t;
47 }
48
49 sum -= 1; /* sum 为当前数组的元素个数*/
50 Qsort(narry,1,sum);
51
52 for(int i = 1; i <= sum;i++)
53 cout << narry[i] << '\t';
54 cout << endl;
55
56 int k;
57 cout <<"please input place you want:"< 58 cin >>k;
59
60 int aa = 1;
61 int kk = 0;
62 for(;;)
63 {
64 if(aa == k)
65 break;
66 if(narry[kk] != narry[kk + 1])
67 {
68 aa += 1;
69 kk++;
70 }
71 }
72
73 cout << "The NO." << k << "number is :" << narry[sum - kk] << endl;
74 return 0;}
如果你可以有更好的办法 期待你来与我共享
阅读(2150) | 评论(0) | 转发(0) |