Gooooogle • 10个月前
#include <stdio.h>
void quickSort(int arr[], int begin, int end) {
if (begin < end) {
int tmp = arr[begin];
int i = begin;
int j = end;
while (i != j) {
while (arr[j] > tmp && j > i)
j--;
while (arr[i] <= tmp && j > i)
i++;
if (j > i) {
int t = arr[i];
arr[i] = arr[j];
arr[j] = t;
}
}
arr[begin] = arr[i];
arr[i] = tmp;
quickSort(arr, begin, i - 1);
quickSort(arr, i + 1, end);
} else
return;
}
int main() {
int num[10000], n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
}
quickSort(num, 0, n - 1);
printf("%d ", num[k - 1]);
return 0;
}
评论:
请先登录,才能进行评论