题目地址:http://oj.tsinsen.com/A1082
int findKth(int *s, int n, int K) { @你的代码 }
#include <stdio.h> int findKth (int * s, int n, int K){ int low = 0; int high = n - 1; int pivot = s[0]; while (low < high){ while (low < high && s[high] >= pivot) --high; s[low] = s[high]; while (low < high && s[low] <= pivot) ++low; s[high] = s[low]; } s[low] = pivot; if (low == K - 1) return s[low]; else if (low > K - 1) return findKth (s, low, K); else return findKth (s + low + 1, n - low - 1, K - low - 1); } int main(void){ int data[10000]; int n; int k; int i; scanf ("%d%d", &n, &k); for (i=0; i<n; ++i) scanf ("%d", &data[i]); printf ("%d\n", findKth (data, n, k)); return 0; }
原文:http://blog.csdn.net/jdplus/article/details/19675351