Question 4(b)(i) 2021 · May-June · Paper 42 · 5 marks
Reveal official mark-scheme answer
Official answer for Question 4
Part (b)
(i)
Question 1
mark for each completed statement (in bold)
Question 5
Show text version of question
Question 4
Part (b)
(i)
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.
(i)
The function Enqueue() takes the value to be added to the queue as a parameter. The
function returns TRUE if the item was added, or FALSE if the queue is full.
Complete the pseudocode for the function Enqueue().
FUNCTION Enqueue(BYVALUE DataToInsert : INTEGER) RETURNS BOOLEAN
IF NumberInQueue > ..............................................
THEN
RETURN FALSE
ELSE
MyNumbers[..............................................] ..............................................
TailIndex ..............................................
IF TailIndex > 9
THEN
TailIndex ..............................................
ENDIF
NumberInQueue NumberInQueue + 1
RETURN TRUE
ENDIF
ENDFUNCTION
Question 14
Why this question appears here
82% assigned-topic match · Programming › Structured programming
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
