Sunday, February 28, 2016

Week 5 SLOG

Hey guys,
    I haven't posted on here for a while because I have been quite busy with my other courses. However, I finally found the time to make a post.
    Week 5 we looked at linked lists. I found them easy to understand, however I had a difficult time coding linked lists. Whenever I asked someone for help with coding them, they would just give me an explanation of what I already understood, but I guess I could not transfer what I understood into code that other people could understand and that would actually work. So what I did was(like always) I spoke to my upper year friend, and he helped me understand how to code linked lists. The part I found difficult coding was the last two lines here:
def __setitem__(self, index, value):
        """
        Set the value of list at position index to value.
 
        Assume self has size at least index + 1.
 
        @param LinkedList self: this LinkedList
        @param index int: position of list to change
        @param object value: new value for linked list
        @rtype: None
        """
        while index < 0 and self.size != 0:
            index += self.size
        new_node = LinkedListNode(value)
        if index >= self.size:
            raise IndexError("index too big!!!")
        elif self.size == 1 and self.front == self.back:
            self.front = self.back = new_node
        else:
            current_node = self.front
            while index > 1:
                current_node = current_node.next_
                index -= 1
            new_node.next_ = current_node.next_.next_
            current_node.next_ = new_node

-Anthony Arena

1 comment:

  1. Don't worry, you'll get the hang of it soon! You always do :)

    ReplyDelete