public static Person FindMatch(Person man)
{
int currentRank = 0;
while (!man.IsMatched())
{
Person woman = man.Preferences[currentRank];
//if that woman is not matched, match them
if (!woman.IsMatched())
{
man.MatchWith(woman);
}
else if (woman.GetRank(man) < woman.MatchRank)
{
//replace the current match with this
Person replaced = woman.CurrentMatch;
// Console.WriteLine("Deleting " + replaced.Name
// + " loves " + woman.Name);
man.MatchWith(woman);
replaced.CurrentMatch = null;
return replaced;
}
currentRank++;
}
return man;
}