Question 4(b)(ii) 2021 · May-June · Paper 42 · 5 marks
Reveal official mark-scheme answer
Official answer for Question 4
Part (b)
(ii)
Question 1
mark per bullet point max 5
Question 5
- Checking if queue is empty/full …
- …and returning −1 if empty
- Incrementing HeadIndex …
- …catching if it goes above 9 and setting to 0
- Decrement NumberInQueue
- returning first element
Show text version of question
Question 4
Part (b)
(ii)
Question 4
Zara is writing a program to simulate a circular queue.
The queue, MyNumbers, has 10 elements. Enqueue() takes a parameter value and stores it at the tail of the queue. Dequeue()returns the item at the head of the queue.
The current state of the circular queue is:
Index 0 1 2 3 4 5 6 7 8 9
Data 31 45 89 500 23 2
HeadIndex: 2
TailIndex: 8 The global array, MyNumbers, is used to store the positive integer numbers for the queue.
The following global variables are used:
- HeadIndex stores the index of the first element in the queue
- TailIndex stores the index of the next free space in the queue
- NumberInQueue stores the number of items in the queue.
(ii)
The function Dequeue() returns the value at the head of the queue, or −1 if the queue
is empty.
Complete the pseudocode for the function Dequeue().
FUNCTION Dequeue() RETURNS INTEGER
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
ENDFUNCTION
Question 15
Why this question appears here
71% assigned-topic match · Programming › Constructs
Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.
Permanent source page: Educate A Change · From 9608_s21_qp_42.pdf
