Problem 1
An animal shelter holds only dogs and cats, and operates on a strictly "first in, first out" basis. People must adopt either the "oldest" (based on a
ival time) of all animals at the shelter, or they can select whether they would prefer a dog or a cat (and will receive the oldest animal of that type). They cannot select which specific animal they
would like. Create the data structures to maintain this system and implement operations such as enqueue, dequeueAny, dequeueDog and dequeueCat. Assume each animal has an unique name and thus you don’t need to wo
y. You need to use at most O(n) storage and O(1) for all operations, where n is the total number of animals in the shelter. Please name your program p8 and you need try all possible tests to make sure your p8 works. Your program should read all t8*.dat in the same directory as your p8.py or p8.ipynb, and generate output for each t8*.dat as the example below.
You need handle whitespace as the whitespace convention and handle e
ors as always. You can only handle cats and dogs, otherwise, print e
or messages and continue for next file if exists. You also need to handle boundary condition, e.g., if dequeue or dequeuAny with no animal left, you should print warning messages like "no more dog/cat left to be adopted". Boundary conditions are counted as co
ectness
points.
Example Input and Output (as comments below) in chronological order:
enqueue(dog, Bark)Â Â Â Â # put the dog named Bark to shelte
enqueue(cat, Mimi) Â Â Â # put the cat named Mimi to shelte
enqueue(cat, Tiger) Â Â Â # put the cat named Tiger to shelte
dequeue(cat)Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â # the cat named Mimi is adopted
dequeueAny()Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â # the dog named Bark is adopted
dequeue(dog) Â Â Â Â Â Â Â Â Â Â Â Â Â Â # no dog left to be adopted
Score:
Co
ectness and boundary condition (60%):
Whitespace convention (5%)
E
or Handling (5%):
Big O notations for all functions: (5%)
Modular design, documentation (25%)