SEC04 - Queue, Stack and Linked Lists
SEC04 - Queue, Stack and Linked Lists
5. Implement the clone() method for the ArrayStack class. Give a big-Oh characterization, in terms
of n, of the running time of this method.
6. Suppose you have a stack S containing n elements and a queue Q that is initially empty. Describe
how you can use Q to scan S to see if it contains a certain element x, with the additional
constraint that your algorithm must return the elements back to S in their original order. You
may only use S, Q, and a constant number of other primitive variables.
7. Stacks are often used to provide “undo” support in applications like a Web browser or text editor.
While support for undo can be implemented with an unbounded stack, many applications
provide only limited support for such an undo history, with a fixed-capacity stack. When push is
invoked with the stack at full capacity, rather than throwing an exception, a more typical
semantic is to accept the pushed element at the top while “leaking” the oldest element from the
bottom of the stack to make room. Give an implementation of such a LeakyStack abstraction,
using a circular array.
8. Repeat the previous problem using a singly linked list for storage, and a maximum capacity
specified as a parameter to the constructor.