快排+返回中位数。水题。
code:
<span style="font-size:18px;">#include <iostream>
#include <fstream>
using namespace std;
void quicksort(int data[],int left,int right)
{
if (left < right)
{
int i = left, j = right, x = data[i];
while (i < j)
{
while (i < j && data[j] >= x)
j--;
if (i < j)
{
data[i++] = data[j];
}
while (i < j && data[i] <= x)
i++;
if (i < j)
{
data[j--] = data[i];
}
}
data[i] = x;
quicksort(data,left,i-1);
quicksort(data,i+1,right);
}
}
int main()
{
//ifstream in("input.txt");
int k,num;
cin >> num;
int *data = new int[num];
for (k = 0; k < num; k++)
{
cin >> data[k];
}
quicksort(data, 0, num - 1);
cout << data[num / 2] << endl;
//system("pause");
return 0;
}</span>