Friday, 13 March 2015

Impressions Of Week 8

On week 8 I learned about linked lists. There are two ways of thinking about linked list structures. The first way is to think of it as lists made of an item and a sub-list. The second way is to think of a linked list as objects with a value and a reference to other similar objects. My way of thinking about it is a train. I think of each section of a train as an object and the head of the train is index zero. First we learned how the node class __init__ method is written. Self.value is the value of the node and self.next is the value of the next node. If we are at the end of the list the value of self.next is None.

We also learned how to write a wrapper class for linked list. The instance variables are self.front; the front of the list, self.back; the back of the list, and self.size; the size of the list. Additionally, we learned that most of the work of special methods is done by the nodes __repr__, __str__, and __eq__. Then, once the special methods are done for the nodes, it’s easy to do them for the entire list.

We were also explained how to write a __contains__ method that checks every node if it has the same value of a specific object. To do that we would have to use a while loop to cycle through all the nodes.

No comments:

Post a Comment