I have a little difficulty in understanding one thing in the structure of the Linked-lists.
Basically nodes of a linked list are created using the following class, and the next reference is obtained by the method getNext():
I have omitted other methods as not relevant to my problem.
self.data = initdata
self.next = None
self.head = None
current = self.head
count = 0
while current != None:
count = count + 1
current = current.getNext() <-----
current is basically an instance of
UnOrderedList in which each element is
Node object. Hence the methods that are applied on
Nodes can be applied on each element of
current. Nodes are added to
UnOrderedList using the add method.
def add(self,item): temp = Node(item) temp.setNext(self.head) self.head = temp