There are two different ways of thinking of linked lists structures. One is to think of it as an item and a sublist and the other is to see it as objects with a value and a reference to other similar objects. We took the second perspective in the class. A new class LLNode was introduced as the object in the second point of view. A LLNode has two attributes value and nxt where value refers to the data it represents and nxt refers to the next LLNode. A LinkedList(formed by LLNodes) has three variables, front, which represents the first node, back, which refers to the last node, and size which stands for the number of the nodes in the LinkedList.
Mutation and iteration are related to LinkedList. For example, in the append method, when a new LLNode is appended to a LinkedList, we will have to change the back node, the former back node, the size of the list and probably the front of the node if the LinkedList is None. As for iterations, for example in the contain method, we have to walk through the list to see if the value is contained in it.
There is a general format for iterations in a LinkedList:
cur_node = self.front
while
No comments:
Post a Comment