Past-paper question · 2021 May-June · Paper 42 · Q4(b)(i)

Question 4(b)(i) 2021 · May-June · Paper 42 · 5 marks

Original past-paper question for 4(B)(I)
Original past-paper question for 4(B)(I)
Original past-paper question for 4(B)(I)
Reveal official mark-scheme answer Official mark-scheme answer for 4(B)(I)

Official answer for Question 4

Part (b)

(i)

Question 1

mark for each completed statement (in bold)

Question 5

✓
FUNCTION Enqueue(BYVAL DataToInsert : INTEGER) RETURNS BOOLEAN
✓
IF NumberInQueue > 9 // = 10
✓
THEN
✓
RETURN False
✓
ELSE
✓
MyNumbers[TailIndex] ← DataToInsert
✓
TailIndex ← TailIndex + 1
✓
IF TailIndex > 9
✓
THEN
✓
TailIndex ← 0
✓
ENDIF
✓
NumberInQueue ← NumberInQueue + 1
✓
RETURN True
✓
ENDIF
✓
ENDFUNCTION
✓
9608/42
✓
Cambridge International AS & A Level – Mark Scheme
✓
May/June 2021
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s21_ms_42.pdf →

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

[5]

Question 14

Topic relevance

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

Keep practising this topic