NAMES:

LOGINS:

PRECEPT:

COS 226 Exercises on Stacks and Queues

References: Lecture 3 and Section 4.3 in IntroJava


1. A letter means enqueue and an asterisk means dequeue in the sequence E A S * Y * Q U E * * * S T * * * I O * N * * * Give the sequence of values returned by the dequeue operations when this sequence of operations is performed on an initially empty FIFO queue.













2. Suppose that a client performs an intermixed sequence of (stack) push and pop operations. The push operations push the integers 0 through 9 in order on to the stack; the pop operations print out the return value. Circle the following sequence(s) that could not occur.

a.  4 3 2 1 0 9 8 7 6 5

b.  2 1 4 3 6 5 8 7 9 0

c.  0 4 6 5 3 8 1 7 2 9

d.  4 6 8 7 5 3 2 9 0 1