Suggested Solution

Task 1 Task 2 Task 3

Task 1

A queue, Q, is implemented by using a 1-dimensional array as follows:

 

The following queue operations are executed:

Q.dequeue()

Q.dequeue()

Q.enqueue("Jones")

Q.dequeue()

Q.enqueue("Jarrod")

Draw the resulting queue and note the address of the front and rear pointers.

Task 2

With reference to the above queue, describe the following operation. Include in your description what happens to the queue pointers.

Make sure you use the vocabulary that you see in the image to help you.

Q.dequeue()

Task 3

Explain the concept of FIFO with reference to queues.

Task 4

A queue, Q, exists.

Write pseudocode that will write the contents of Q to a fixed-length array, ARR.

The algorithm will stop when either the array is full or the Q is empty!

Implement this algorithm.

Task 5

A function, reverseQueue, processes a queue, Q. It reverses the order of items in Q. In order to do this, it utilises an empty stack, S.

Write pseudocode that will implement reverseQueue. Its signature is:

function reverseQueue(Q)