0% found this document useful (0 votes)
118 views2 pages

Assignment Queue

The document discusses queues and priority queues. It contains 3 questions about the order elements would be removed from different queue data structures after various enqueue and dequeue operations. The answers provided are the contents of the queues after each set of operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views2 pages

Assignment Queue

The document discusses queues and priority queues. It contains 3 questions about the order elements would be removed from different queue data structures after various enqueue and dequeue operations. The answers provided are the contents of the queues after each set of operations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

Korallys Rodríguez February 25, 2020.

COMP 2900 Prof. Donato

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?

QueueInterface myQueue = new LinkedQueue<>();

myQueue.enqueue("Jane");

myQueue.enqueue("Jess");

myQueue.enqueue("Jill");

myQueue.enqueue(myQueue.dequeue());

myQueue.enqueue(myQueue.getFront());

myQueue.enqueue("Jim");

String name = myQueue.dequeue();

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.

PriorityQueueInterface myPriorityQueue = new LinkedPriorityQueue<>();

myPriorityQueue.add("Jim");

myPriorityQueue.add("Jess");

myPriorityQueue.add("Jill");

myPriorityQueue.add("Jane");

String name = myPriorityQueue.remove();

myPriorityQueue.add(name);

myPriorityQueue.add(myPriorityQueue.peek());

myPriorityQueue.add("Jim");

myPriorityQueue.remove();

Answer:

You might also like