Assignment Queue
Assignment Queue
Assignment: Queues
1. If you add the objects x, y, and z to an initially empty queue, in what order will three dequeue
operations remove them from the queue?
Answer:
x y z
y z
z
2. After the following statements execute, what are the contents of the queue?
myQueue.enqueue("Jane");
myQueue.enqueue("Jess");
myQueue.enqueue("Jill");
myQueue.enqueue(myQueue.dequeue());
myQueue.enqueue(myQueue.getFront());
myQueue.enqueue("Jim");
myQueue.enqueue(myQueue.getFront());
Answer:
Jane
Jane Jess
Jane Jess Jill
Jess Jill Jane
Jess Jill Jane Jess
Jess Jill Jane Jess Jim
Jill Jane Jess Jim
Jill Jane Jess Jim Jill
3. After the following statements execute, what are the contents of the priority queue? Assume that the
alphabetically earliest string has the highest priority.
myPriorityQueue.add("Jim");
myPriorityQueue.add("Jess");
myPriorityQueue.add("Jill");
myPriorityQueue.add("Jane");
myPriorityQueue.add(name);
myPriorityQueue.add(myPriorityQueue.peek());
myPriorityQueue.add("Jim");
myPriorityQueue.remove();
Answer: