Thursday, February 23, 2012

Assign Phone numbers to people.


Suppose you are working for a phone company and you run the division that gives out phone numbers. Phone numbers are assigned in one of two ways:
a. bool GiveMeThisNumber(Person p, int number) Assigns the person a specific number that they requested, returning true if the number is available.
b. int GiveMeAnyNumber(Person p) Assigns the person any arbitrary number that is currently unassigned.
How would you design the algorithm for those methods? You can use any data structure you would like to hold the phone numbers.
Implement GiveMeThisNumber and GiveMeAnyNumber.

No comments:

Post a Comment