Back to Challenge Set 19

Code Challenge: Box Office

Difficulty  

divider

The Brief

What they asked for
Box office. Someone walks up with a seat number and I need to
know fast whether it has been sold. The sold list is kept in
order. Do not make me wait while it checks all of them.

Write your requirements list before you write any code. Input, calculate, output, and anything you had to decide for yourself.


Notes

  • Kept in order is the whole brief. That phrase is what lets you use binary search.
  • Do not trust it. Write a check that confirms the array is sorted before you search it, and say what your program does if it is not.
  • Report the number of checks, so the box office can see the difference.
  • Handle a seat number that was never sold.

Sample Output

Sample Output
Sold list is in order.
Seat 55: sold (3 checks)
Seat 12: sold (3 checks)
Seat 50: available (3 checks)

Seven sold seats, so binary search never needs more than three checks. Try your sorted check on an array with two seats swapped.


Submit

Your requirements list and your program file, named cc-box-office.

Commence Challenge