In my classmate's post (http://adamosslog.blogspot.ca/), he wrote that " it is useful to have a variable that keeps track of the node that was "visited" just before the current node, so that you can do things like delete the current node by connecting the previous node to one just after the current. ". I agree with his idea. It is very important to keep track of the node; otherwise I have to keep finding the node, which is very inefficient.
Moreover, I realized that linked list is very different from regular list object. Basically the class allows us to create objects with two instance names: value refers to some object (of any class) but next should either refer to an object constructed from the LN class or refer to None (its default value). Linked list has shorter running time than regular list.
In general:
(1) x stores a reference to the first LN object
(2) x.value stores a reference to the int object 5
(3) x.next stores a reference to the second LN object
(4) x.next.value stores a reference to the int object 3 in this second LN
object
(5) x.next.next stores a reference to the third LN object
(4) x.next.next.value stores a reference to the int object 8 in this third
LN object
No comments:
Post a Comment