Lab 9 Queue Part 1
Lab 9 Queue Part 1
4. What would be the content of queue of Q1 and the output after the following code is
executed? Assume the size of Q1 1s 10.
1 Q1 = createQueue
2 Enqueue (‘G’)
3 Enqueue (‘I’)
4 Enqueue (‘R’)
5 Enqueue (‘I’)
6 Enqueue (‘F’)
7 Enqueue (‘F’)
8 Dequeue ()
9 Dequeue ()
10 Print (QueueFront)
11 Print (QueueRear)
12 Enqueue (‘A’)
13 Enqueue (‘H’)
14 Dequeue ()
15 Print (QueueFront)
16 Print (QueueRear)
17 End
Output:
RFIH
pg115
5. What would be the content of Q after the following is executed and the following data are
entered? Assume the size of Q1 is 20. The data are: 5 7 12 4 0 6 8 67 0 5 44 33
1 Q = CreateQueue
2 Loop (until end of data)
2.1 Read number
2.2 If (number not 0)
2.2.1 Enqueue (number)
2.3 Else
2.3.1 x = QueueRear
2.3.2 Enqueue (x)
2.4 End if
3 End loop
Content of Q:
5 7 12 4 4 6 8 6 67 5 44 33
7
0 1 2 3 4 5 6 7 8 9 10 11 count = 12
6. Imagine you have a stack of integers, S, and queue of integers, Q. Draw a picture of S and
Q after the following operations:
1 Push (3)
2 Push (12)
3 Enqueue (5)
4 Enqueue (8)
5 x = Pop ()
6 Push (2)
7 Enqueue (x)
8 y = Dequeue
9 Push (x)
10 Push (y)
5 3
12 2
2 1
3 0
S count = 4
Q
8 12
0 1 2 count = 2