A program uses a circular queue to store strings. The queue is created as a 1D array, QueueArray, with 10 string items. The following data is stored about the queue: • the head pointer initialised to 0 • the tail pointer initialised to 0 • the number of items in the queue initialised to 0.
- (a)Declare the array, head pointer, tail pointer and number of items. If you are writing in Python, include attribute declarations using comments. Save your program as Question3_J2022. Copy and paste the program code into part 3(a) in the evidence document.[2]
- (b)The function Enqueue is written in pseudocode. The function adds DataToAdd to the queue. It returns FALSE if the queue is full and returns TRUE if the item is added. The function is incomplete, there are five incomplete statements. FUNCTION Enqueue(BYREF QueueArray() : STRING, BYREF HeadPointer : INTEGER, BYREF TailPointer : INTEGER, NumberItems : INTEGER, DataToAdd : STRING) RETURNS BOOLEAN IF NumberItems = THEN RETURN ENDIF QueueArray[... DataToAdd IF TailPointer >= 9 THEN TailPointer ELSE TailPointer ← TailPointer + 1 ENDIF NumberItems ← NumberItems RETURN TRUE ENDFUNCTION Write program code for the function Enqueue(). Save your program. Copy and paste the program code into part 3(b) in the evidence document.[7]
- (c)The function Dequeue() returns "FALSE" if the queue is empty, or it returns the next data item in the queue. Write program code for the function Dequeue(). Save your program. Copy and paste the program code into part 3(c) in the evidence document.[6]
- (d)(i)Amend the main program to: • take as input 11 string values from the user • use the Enqueue () function to add each element to the queue • output an appropriate message to state whether each addition was successful, or not • call Dequeue() function twice and output the return value each time. Save your program. Copy and paste the program code into part 3(d)(i) in the evidence document.[5]
- (d)(ii)Test your program with the input data: "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" Take a screenshot to show the output. Copy and paste the screenshot into part 3(d)(ii) in the evidence document.[1]
Mark scheme
Marking points from the official mark scheme (May/June 2022). The mark or mark type is shown in brackets.
- [1] Declaring variables: head pointer, tail pointer and number of items all initialised as 0 (integer)
- [1] QueueArray declared as 1D array as string with 10 elements
- [1] function heading and end, dealing with ByRef parameters
- [1] IF NumberItems = 10 THEN
- [1] RETURN FALSE
- [1] QueueArray[TailPointer] ← DataToAdd
- [1] IF TailPointer >= 9 THEN TailPointer ← 0 ELSE TailPointer ← TailPointer + 1 ENDIF (or equivalent modulo arithmetic)
- [1] NumberItems ← NumberItems + 1
- [1] RETURN TRUE
- [1] Function header and end
- [1] checking if queue is empty ...
- [1] returning False
- [1] If not empty accessing and returning item at head pointer
- [1] incrementing head pointer ...
- [1] changing head pointer to 0 if it's more than 9 after incrementing
- [1] decrement number of items
- [1] Taking 11 inputs...
- [1] calling Enqueue with each of the 11 inputs ...
- [1] outputting an appropriate message if added or not added
- [1] Calling Dequeue twice
- [1] ... outputting return value each time
- [1] 1 mark for showing inputs and outputs: A - J input and successful. K input and unsuccessful. Output: A, B
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →