Congratulations, you have implemented a linked list in Python!
We did this by:
- Defining a
Nodeclass to hold the values and links between nodes
- Implementing a
LinkedListclass to handle external operations on the list like adding and removing nodes
Feel free to play around a bit with your code. Here are some ideas:
- Create a few nodes and adding them to a new linked list
- Print your linked list out by using your
- Remove your linked list’s head node
- Print your list again — was your original head node removed?
- So far you’ve built a method to remove the first occurrence of a given value. How do you think you would remove all nodes that have a specific value? Try building a method to do that!