Y13 Programming
Linked Lists
This website scaffolds an OCR-style Question using Python.
It includes:
- The necessary Python class code so you can run and test your methods
- Hidden model answers (click to reveal)
- Test programs for each sections to ensure that your code works.
Python Runtime: Loading...
Main Python Code
The code below provides:
- the class structures
- placeholders for the methods you will complete in each subsequent question
Main code output will appear here.
Question 1(a)(i)
Task:
- Implement
getNextNode()so it returns the attributenextNode. - Complete the method inside the
nodeclass in the starter code. - Run this test to check your code works.
Test output will appear here.
Show model answer for 1(a)(i)
Question 1(a)(ii)
Task:
- Implement
setValue(newValue)so it assigns the parameter to the attributevalue. - Complete the method inside the
nodeclass in the starter code. - Run this test to check your code works.
Test output will appear here.
Show model answer for 1(a)(ii)
Question 1(b)
Task:
- Complete the method
outputList()inside thelinkedListclass in the starter code. - Start at
headNodeand traverse until there are no more nodes. - Build a string containing each node value followed by a space, and return the final string.
- Run this test to check your code works.
Test output will appear here.
Show model answer for 1(b)
Question 1(c)
Task: Write an algorithm to create a new linkedList object with identifier
createList, insert 10, 25, and 39 in this order, then output
the contents of the list using the appropriate method.
Test output will appear here.