POJ2388#快排水题

来源:互联网 发布:一键领取cf装备源码 编辑:程序博客网 时间:2024/04/26 00:15
#include <iostream>using namespace std;void quickSort(int seq[], int begin, int end){if (begin < end){int temp = seq[begin];//挖坑int i = begin;int j = end;while (i < j){while (i < j && seq[j] > temp)//从后往前找到小于temp的数{j--;}if (i < j){seq[i++] = seq[j];}while (i < j && seq[i] < temp)//从前往后找到大于temp的数{i++;}if (i < j){seq[j--] = seq[i];}}//将之前挖出来的数放到适合的位置seq[i] = temp;//递归quickSort(seq, begin, i - 1);quickSort(seq, i + 1, end);}}int main(){int n;cin >> n;int seq[99999];for (int i = 0; i < n; i++){cin >> seq[i];}quickSort(seq, 0, n - 1);cout << seq[(n - 1) / 2] << endl;}

0 0