Past-paper question · 2024 October-November · Paper 42 · Q2(c)

Question 2(c) 2024 · October-November · Paper 42 · 5 marks

Question 2

Part (c)

Question 2

A linear queue data structure is designed using a record structure.

The record structure Queue has the following fields:

  • QueueArray, a 1D array of up to 100 integer values
  • Headpointer, a variable that stores the index of the first data item in QueueArray
  • Tailpointer, a variable that stores the index of the next free location in QueueArray.

Part (c)

The pseudocode function Enqueue() inserts an integer value into the queue.

The function is incomplete. There are three incomplete statements.

FUNCTION Enqueue(BYREF AQueue : Queue, BYVAL TheData : INTEGER) RETURNS INTEGER

IF AQueue.Headpointer = -1 THEN

AQueue.QueueArray[AQueue.Tailpointer] ← ........................................ AQueue.Headpointer ←0 AQueue.Tailpointer ← AQueue.Tailpointer + 1

RETURN 1

ELSE

IF AQueue.Tailpointer > ........................................ THEN

RETURN -1

ELSE

AQueue.QueueArray[AQueue.Tailpointer] ← TheData AQueue.Tailpointer ← AQueue.Tailpointer ........................................ RETURN 1

ENDIF

ENDIF

ENDFUNCTION

Write program code for Enqueue().

Save your program.

Copy and paste the program code into part 2(c) in the evidence document.

[5]
Reveal official mark-scheme answer Official mark-scheme answer for 2(C)

Official answer for Question 2

Part (c)

Question 1

mark for each completed statement to max 3

Question 5

✓
1 mark for correct values returned in correct places
✓
1 mark for function header taking (at least) one parameter and the rest of function correct and using the record/class data
✓
structure accurately.
✓
Pseudocode
✓
FUNCTION Enqueue(BYREF AQueue : Queue, BYVAL TheData : INTEGER)
✓
RETURNS INTEGER
✓
IF AQueue.HeadPointer = -1 THEN
✓
AQueue.QueueArray[AQueue.TailPointer] TheData
✓
AQueue.HeadPointer 0
✓
AQueue.TailPointer AQueue.TailPointer + 1
✓
RETURN 1
✓
ELSE
✓
IF AQueue.TailPointer > 99 THEN
✓
RETURN -1
✓
ELSE
✓
AQueue.QueueArray[AQueue.TailPointer] TheData
✓
AQueue.TailPointer AQueue.TailPointer + 1
✓
RETURN 1
✓
ENDIF
✓
ENDIF
✓
ENDFUNCTION
✓
Cambridge International AS & A Level – Mark Scheme
✓
9618/42
✓
October/November 2024
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9618_w24_ms_42.pdf →

Topic relevance

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 9618_w24_qp_42.pdf

Keep practising this topic