Matching Algorithm (from Book):
Initially all m in M and w in W are unmatched
While there is a man m in M who is not engaged
choose such a man m
while m is not engaged
Let w in W be the highest-ranked woman
in M's
preference list
to whom m
has not yet proposed
If w is not engaged
engage m with w
else
if w is currently engaged
to m' and w
prefers m to m'
engage m with w and make
m' unengaged
end if
mark w as
"has been proposed to"
end if-then-else
end while
end While
Note that this means we need to have:
1. Preferences of men for women and women for men
2. A set containing men who are not engaged
3. A set, easily accessible, of engaged men and women
Note the obvious choice for 1 is probably 2-d arrays.
For 2, we could use almost any dynamic structure which is
fast for both retrieving a member and storing a
member.
For 3 a hash map is an obvious choice, although we could
use an ordinary array. We want to be able to quickly
find
out if a given woman is engaged and, if so, to whom.