|
int x; // next input value
int maj; // The current solution
int count = 0; // Excess count
while ( input stream ≠ empty )
{
x = read(input stream);
if ( count == 0 )
{
maj = x; // New candiate
count = 1; // Count of candidate
}
else
{ /* ------------------------------------------
count > 0 (we have a current solution)
------------------------------------------ */
if ( x == maj )
{
count++; // Increase the certainty that solution is correct
}
else
{
count--; // Decrease the certainty that current solution is correct
}
}
}
print(maj);
|
Note:
|