Question 3

OCR Computer Science June 2023 Algorithms and programming (H446-02)A level18 marks

On the specification

(a)
1.4 Data types, data structures and algorithms
(b)
1.4 Data types, data structures and algorithms
(c)
2.3 Algorithms
(d)
2.3 Algorithms
(e)
2.3 Algorithms
Question text

3 A program stores data in a linked list. The current contents of the linked list are shown in Fig. 3, along with the linked list pointers. location data pointer headPointer 1 0 "blue" 6 freeListPointer 4 1 "red" 0 2 "green" 8 3 "orange" NULL 45 57 6 "grey" 2 79 8 "purple" 3 9 NULL Fig. 3 (a) State the purpose of headPointer and freeListPointer in the linked list shown in Fig. 3. headPointer freeListPointer [2] (b) State the meaning of the pointers with the value NULL in the linked list shown in Fig. 3. [1] (c) A procedure outputs the data in the linked list shown in Fig. 3 from the first item in the list, to the last item. Give the output from the procedure. [2] (d) A new item needs to be added to the linked list. Describe how a new item is added to a linked list. [4] (e) The function findNode will search the linked list and return either the position of the node that contains the data item, or -1 if the data item is not found. The data held in a node at location x can be accessed with linkedList[x].data. The pointer of the node at location x can be accessed with linkedList[x].pointer. For example, using the linked list shown in Fig. 3: linkedList[2].data returns green. linkedList[2].pointer returns 8. Complete the function, using pseudocode or program code. function findNode(toFind, headPointer, linkedList) currentNode = while(currentNode != ) if linkedList[currentNode]. == toFind then return currentNode else currentNode = linkedList[ ].pointer endif endwhile return endfunction [5]