A linked list contains a series of elements--nodes--connected by pointers. Each node object consists of two pieces of information--two instance variables:
data
= the information contained in the nodenext
= a pointer to the next Node
, if one existsWrite a Node
class that includes a constructor, and four methods that will allow us to interact with those variables: two "getters" and two "setters".
get_data()
= returns the data of this nodeget_next()
= the pointer to the next node in the unordered listset_data()
= allows for altering the data at this Nodeset_next()
= allows for resetting the pointer from this Node to a different NodeThe constructor for a new Node object takes an initial piece of data as a parameter, but that there is no initial next that we point to. Make sure to set the initial pointer to None
explicitly.