Sunday, March 23, 2014

Week 8

  In Week 7 and Week 8, we focused on the topic LinkedList during the lecture and the lab. LinkedList is an interesting data structure, and it is recursively defined. LinkedList is made up of nodes which contain a reference to the next one, and this kind of data is called cargo. During the lab, I have learnt many methods dealing with the LinkedList, like how to add new item to front of the LinkedList, delete item from LinkedList, check whether a LinkedList contains a specific value and find out the position (index) of the value or item in the the LinkedList. The following code is an example of the class LinkedList:


class LinkedList:
    """Linked list class"""

    def __init__(self: 'LinkedList', item: object=None,
                 rest: 'LinkedList'=None) -> None:
        """Create a new LinkedList
        item - The first element of the linked list,
        Not present if self will be the empty linked list.
        rest - The linked list that contains the elements after item.
        Not present if self will be the empty linked list."""
        self.empty = (item is None) and (rest is None)
        if not self.empty:
            self.item = item
            if rest is None:
                self.rest = LinkedList()
            else:
                self.rest = rest
This week's lab is more easier for my partner and I to finish, because we have read and learnt more materials of LinkedList. To learn this stuff well, we should always think carefully about the recursion method. A few weeks are left, I think I should practise more to think up the code much more quickly and correctly.

No comments:

Post a Comment