poj2388

来源:互联网 发布:创维网络电视机 编辑:程序博客网 时间:2024/06/05 14:25
#include<iostream>
#include<string>
using namespace std;


void qsort(int,int);
int arr[10000] = { 0 };
int n = 0;
int main()
{

cin >> n;
int temp;
for(int i=0;i<n;i++)
{
cin >> temp;
arr[i] = temp;
}

qsort(0,n);


cout << arr[n / 2 + 1];




}




void qsort(int l,int r)
{
if(l<r)
{
int i = l, j = r, x = arr[i];
while (i < j)
{
while (i < j&&arr[j] >= x)
j--;
if (i < j)
arr[i++] = arr[j];
while (i < j&&arr[i] <= x)
i++;
if (i < j)
arr[j--] = arr[i];
}
arr[i] = x;
qsort(l, i-1);
qsort(i+1, r);
}


}
原创粉丝点击