9618/43 · May/June 2025
Download PDFA program reads data from a text file and stores it in a queue. The linear queue Queue is stored as a 1D array of up to 50 elements. The queue has the following pointers: • HeadPointer – this stores the index of the first element in the queue, initialised to –1 • TailPointer – this stores the index of the last element in the queue, initialised to –1
Queue is a global array of 50 integers with all elements initialised to –1 in the main program. The two pointers are declared as global variables and initialised to –1 Write program code to declare and initialise Queue, HeadPointer and TailPointer Save your program as Question1_J25. Copy and paste the program code into part 1(a) in the evidence document.
The function Enqueue(): • takes an integer parameter to store in the next position in the queue • returns FALSE if the queue is full and the parameter cannot be stored in the queue • returns TRUE if the parameter is stored in the queue • updates the pointers where appropriate. Write program code for Enqueue() Save your program. Copy and paste the program code into part 1(b) in the evidence document.
The function Dequeue(): • returns the next item in the queue, if the queue is not empty • returns –1 if the queue is empty • updates the pointers where appropriate. Write program code for Dequeue() Save your program. Copy and paste the program code into part 1(c) in the evidence document.
The text file QueueData.txt stores positive integers. Each integer is on a new line in the file. The procedure CreateQueue(): • opens the file QueueData.txt • reads in each line from the text file and uses Enqueue() to insert each line into the queue • outputs "Queue full" if any item cannot be inserted into the queue • uses exception handling when opening and reading from the text file. The procedure needs to work for a file that contains an unknown number of lines. Write program code for CreateQueue() Save your program. Copy and paste the program code into part 1(d) in the evidence document.
The main program needs extending to call CreateQueue(). The main program then adds together all of the integers stored in the queue, using Dequeue() to access each integer. The total is then output. Write program code to extend the main program. Save your program. Copy and paste the program code into part 1(e)(i) in the evidence document.
Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 1(e)(ii) in the evidence document.
A program sorts the data in the 1D array DataArray and searches DataArray for specific values. DataArray stores 14 integer values and is declared local to the main program.
Write program code to create DataArray and initialise it with the following data values in the order they are written: 0 3 4 56 67 44 43 32 31 345 45 6 54 1 Save your program as Question2_J25. Copy and paste the program code into part 2(a) in the evidence document.
The function InsertionSort() takes an array of integers as a parameter. The function sorts the data in the array into ascending numerical order using an insertion sort. The function returns the sorted array. Write program code for InsertionSort() You must not use any inbuilt sorting functions for your programming language. Save your program. Copy and paste the program code into part 2(b) in the evidence document.
The procedure OutputArray() takes an array of integers as a parameter. The procedure outputs each element in the array from the first element to the last element. The output is on one line with a space between each number. An example output is: "0 3 4 56 67 44 43 32 31 345 45 6 54 1" Write program code for OutputArray() Save your program. Copy and paste the program code into part 2(c) in the evidence document.
The main program needs extending to: • output the content of the unsorted array using OutputArray() • sort the array using InsertionSort() • output the content of the sorted array using OutputArray() Write program code to extend the main program. Save your program. Copy and paste the program code into part 2(d)(i) in the evidence document.
Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 2(d)(ii) in the evidence document.
The function Search() performs a binary search to find ItemToFind in DataArray The function takes two parameters: • DataArray, an array of integers • ItemToFind, an integer to find in DataArray The function returns: • the index of ItemToFind if it is in DataArray • –1 if ItemToFind is not in DataArray Write program code for Search() You must not use any inbuilt searching functions for your programming language. Save your program. Copy and paste the program code into part 2(e) in the evidence document.
The main program needs extending to call Search() with the sorted array four times: • the first time to find the index of the integer 0 • the second time to find the index of the integer 345 • the third time to find the index of the integer 67 • the fourth time to find the index of the integer 2 If the integer is found in the array, output an appropriate message that includes the index. If the integer is not found, output that it was not found. Write program code to extend the main program. Save your program. Copy and paste the program code into part 2(f)(i) in the evidence document.
Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 2(f)(ii) in the evidence document.
A program stores data in a linked list that is designed using Object‑Oriented Programming (OOP). The class Node stores data about the nodes. Node TheData : Integer stores the integer data NextNode : Node stores the next node in the linked list Constructor() initialises TheData to its parameter value, initialises NextNode to a null value GetData() returns TheData GetNextNode() returns NextNode SetNextNode() takes an object of type Node as a parameter and stores it in NextNode
Write program code to declare the class Node and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program as Question3_J25. Copy and paste the program code into part 3(a)(i) in the evidence document.
Write program code for the two get methods. Save your program. Copy and paste the program code into part 3(a)(ii) in the evidence document.
The method SetNextNode() takes an object of type Node as a parameter. The method stores the parameter in the attribute NextNode Write program code for SetNextNode() Save your program. Copy and paste the program code into part 3(a)(iii) in the evidence document.
The class LinkedList stores the linked list. LinkedList HeadNode : Node stores the first node in the linked list Constructor() initialises HeadNode to a null value InsertNode() creates a new node using its integer parameter. Sets this node as the new head node and updates NextNode RemoveNode() finds the first node that contains its integer parameter and removes this node from the linked list Traverse() concatenates and returns the integer data in each node in the linked list Write program code to declare the class LinkedList and its constructor. Do not declare the other methods. Use your programming language appropriate constructor. If you are writing in Python, include attribute declarations using comments. Save your program. Copy and paste the program code into part 3(b)(i) in the evidence document.
The method InsertNode(): • takes an integer as a parameter • creates a new node with the parameter as the integer data • uses the new node’s method SetNextNode() to store the current HeadNode as the next node • replaces HeadNode with the current node. Write program code for InsertNode() Save your program. Copy and paste the program code into part 3(b)(ii) in the evidence document.
The method Traverse() concatenates the integer data from the nodes in the linked list, starting with the node stored in HeadNode. The method returns the final string with each integer data separated with a space. Write program code for Traverse() Save your program. Copy and paste the program code into part 3(b)(iii) in the evidence document.
The method RemoveNode() takes an integer parameter to search for and remove from the linked list. The method first checks if the linked list is empty. If the linked list is empty the method returns FALSE If the linked list is not empty, the integer data in HeadNode is compared to the parameter. If it matches the parameter, HeadNode is changed to store the next node. If the parameter does not match, the nodes are followed until either: • the node with matching integer data is found. This node is removed, the appropriate nodes updated and TRUE returned or • none of the nodes contain matching integer data to the parameter. No nodes are removed and FALSE is returned. Write program code for RemoveNode() Save your program. Copy and paste the program code into part 3(b)(iv) in the evidence document.
The main program creates a new LinkedList object and uses the appropriate method to insert five nodes with the following integer data values in the order given: 10 20 30 40 50 The main program then: • calls Traverse() • removes the node containing the integer data 30 using RemoveNode() • calls Traverse() Write program code for the main program. Save your program. Copy and paste the program code into part 3(c)(i) in the evidence document.
Test your program. Take a screenshot of the output(s). Save your program. Copy and paste the screenshot into part 3(c)(ii) in the evidence document.






