ID:195022
 
// Title:          List Majority
// Credit to: Dipstyx
// Contributed by: Dipstyx

/*
This method can be used to determine which element in a collection
appears most often. It uses one pass, so it is very efficient.

Occassionally it will return the last item found that has equal weight
with another element (a "tie" in terms of the number of appearances).
This procedure should only be used if it can be assumed that there is
actually one majority in the collection. OTherwise, another pass will
need to be performed.
*/


proc/findMajority(var/list/l)
{
var/candidate = null;
var/count = 0;

for(var/i in l)
{
if(count == 0)
{
count = 1;
candidate = i;
}
else if(candidate == i) count ++;
else count --;
}

return candidate;
}