Question 4(c)(vi) 2017 · May-June · Paper 41 · 6 marks
Reveal official mark-scheme answer
Official answer for Question 4
Part (c)
(vi)
- Store free list pointer as NewNodePointer
- Store new data item in free node
- Adjust free pointer
- F list is currently empty
- Make the node the first node
- Set pointer of this node to Null Pointer
- Find insertion point
- If previous pointer is Null pointer
- Link this node to front of list
- Link new node between Previous node and next node
Show text version of question
Question 4
Part (c)
(vi)
Question 4
An ordered linked list Abstract Data Type (ADT) has these associated operations:
- create list
- add item to list
- output list to console
The ADT is to be implemented using object-oriented programming as a linked list of nodes.
Each node consists of data and a pointer. The identifier table for the LinkedList class is:
Identifier Data type Description HeadPointer INTEGER Pointer to the first node in the ordered list. FreeListPointer INTEGER Pointer to the first node in the free list. NodeArray ARRAY[0 : 7] OF Node 1D array stores the nodes that make the ordered linked list. The unused nodes are linked together into a free list. Constructor() Constructor instantiates an object of LinkedList class, initialises HeadPointer to be a null pointer and links all nodes to form the free list. FindInsertionPoint() Procedure that takes the new data item as the parameter NewData and returns two parameters:
- PreviousPointer, whose value is:
- NextPointer, whose value is a
either pointer to node before the insertion point or the null pointer if the new node is to be inserted at the beginning of the list.
pointer to node after the insertion point. AddToList(NewString) Procedure that takes as a parameter a unique string and links it into the correct position in the ordered list. OutputListToConsole() Procedure to output all the data from the list pointed to by HeadPointer.
The following diagram shows an example of a linked list object. This example list consists of three nodes, linked in alphabetical order of the data strings. The unused nodes are linked to form a free list.
HeadPointer Berlin London Paris Ø node node node
FreeListPointer Ø node node node node
The symbol O represents a null pointer.
(vi)
The structured English for the AddToList(NewString) method is as follows:
Make a copy of the value of free list pointer, name it NewNodePointer
Store new data item in free node pointed to by NewNodePointer
Adjust free list pointer to point to next free node
IF linked list is currently empty
THEN
Make this node the first node
Set pointer of this node to null pointer
ELSE
Find insertion point using the FindInsertionPoint method
// FindInsertionPoint provides
// pointer to previous node and pointer to next node
IF previous pointer is null pointer
THEN
Link this node to front of list
ELSE
Link this node between previous node and next node
The FindInsertionPoint method receives the new data item as the parameter NewString. It returns two parameters:
- PreviousPointer, whose value is:
- NextPointer, whose value is the pointer to the node after the insertion point.
either the pointer to the node before the insertion point or the null pointer, if the new node is to be inserted at the beginning of the list.
Question 15
Write program code for the AddToList method.
Programming language used ............................................................................................
Program code
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
.......................................................................................................................................[6]
Question 16
reasonable effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.
Why this question appears here
98% assigned-topic match · Further programming › Programming paradigms
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_s17_qp_41.pdf
