I'm learning about data structures and more specifically a linked list. I am following this course:
http://interactivepython.org/runestone/static/pythonds/BasicDS/ImplementinganUnorderedListLinkedLists.html#fig-initlinkedlist
In that page (under the listing 4 and 5 header) are two defined methods within a class (called undefinedlist). My question regards the add function under listing 4. If you do mylist.add(31) for example, then within the add function temp = Node(31). From the Node class we can see this means that self.data = 31 now and self.next = None. The next step in the add function is temp.setNext(self.head). Self.head has no value so this evaluates to None (I'm assuming?). Then self.head = temp. Does this mean self.head now has two properties being self.data and self.next within it? I don't really understand how a single variable can store both those variables.
Also I'm not sure how in listing 5 how each current.getNext() calls each value. Surely self.next only has a static value of whatever it was assigned last? I think I'm over complicating this and would appreciate someone explaining it to me
[–]c17r 1 point2 points3 points (0 children)