Friday, 12 February 2016

Week 5

We had our first term test this week. Unfortunately, I was one of those who did not give the test due to a fire alarm that rang as soon as the test began. The test was quite easy, I would have easily gotten a good grade. This week we studied about linked lists, which i felt was the most difficult topic that we have done till now. Linked lists are linear sequences of nodes. We defined two classes in lecture; LLNode, to represent a single node and a wrapper class, LinkedList, to represent the list as a whole. We also talked about traversing a linked list and mutating a linked structure. In the LinkedList class we implemented functions to prepend and a contains function. the professor gave very good examples to aid our understanding. He chose a few students and pretended that they were lists linked to each other. So, that was very helpful. This week's lab was also on linked list, we had to write a few methods for them. Linked lists are very confusing, one needs a lot of pictures to understand them. It is very easy to mess up. The quiz was also on this topic, which i did not know how to do. I will have to practice more questions on this topic. I am quite stressed about what Danny and the department will decide about our term test. Assignment 1 is also due after the reading week, I hope my partner and I do well on it. Here is an example of a linked list and the code for the contains function:


 def __contains__(self, value):
        ''' (LinkedList, object) -> bool
    
        Return whether LinkedList (self) contains value.
    
        >>> lnk = LinkedList()
        >>> lnk.prepend(0)
        >>> lnk.prepend(1)
        >>> lnk.prepend(2)
        >>> lnk.__contains__(1)
        True
        >>> lnk.__contains__(3)
        False
        '''
        current_node = self.front
        while current_node:
            if value == current_node.value:
                return True
            current_node = current_node.nxt
        return False    

No comments:

Post a Comment