找中间数问题

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int getMiddleValue(const int *p,int size)
{
int counter[100] = {0};
for(int i = 0;i < size;++ i)
{
++ counter[p[i]];
}
int tempCounter = 0;
for(int i = 0;i < 100;++ i)
{
tempCounter += counter[i];
int data = size >> 1;
if(tempCounter > data )
return i;
}
return 0;
}
void main()
{
int a[5]= {1,10,30,28,99};
cout<<getMiddleValue(a,5);
system("pause");
}
posted @ 2013-05-09 17:36  byfei  阅读(119)  评论(0编辑  收藏  举报