/*
* @filename: MoreThanHalfNum.cpp
* @author: Tanswer
* @date: 2018å¹´02æ25æ¥ 21:01:24
* @description:
*/
#include
#include "Partition.h"
using namespace std;
bool g_bInputInvalid = false;
bool CheckMoreThanHalf(int* numbers, int length, int result)
{
int count = 0;
for(int i=0; i> 1;
int index = Partition(numbers, length, start,end);
while(index != middle)
{
if(index > middle)
{
end = index - 1;
index = Partition(numbers, length, start, end);
}
else
{
start = index + 1;
index = Partition(numbers, length, start, end);
}
}
int result = numbers[middle];
if(!CheckMoreThanHalf(numbers, length, result))
result = 0;
return result;
}
int main()
{
int numbers[9] = {1,2,3,2,2,2,5,4,2};
cout << MoreThanHalfNum_1(numbers,9) << endl;
cout << MoreThanHalfNum_2(numbers,9) << endl;
return 0;
}