Saturday, March 7, 2015

Week 8 slog


The impression of this week
This week’s lectures focus on linked lists. And I find that I don't fully grasp the materials about linked lists presented in lectures.  Unfortunately, due to the CUPE 3902 strike, we no longer have tutorials to seek assistance. Based on CSC148's Information Sheet, I expect the term test 2 will occur next week, so we probably will be tested on linked lists. 


    def append(lnk, value):
        ''' (LinkedList, object) -> NoneType

        Insert a new node with value at back of lnk.

        >>> lnk = LinkedList()
        >>> lnk.append(5)
        >>> lnk.size
        1
        >>> print(lnk.front)
        5 ->|
             '''
        new_node = LLNode(value)
        if lnk.back:
            lnk.back.nxt = new_node
            lnk.back = new_node
        else:
            lnk.back = lnk.front = new_node
        lnk.size += 1

As shown above the method in link list,  my doubt is that after assigning new_node
to lnk.back.nxt, why not set lnk. back = lnk.front? After checking lnk.front and lnk. back , I find they are same at this step.


My plan 
  My plan is to review some lecture notes before the exam and to re-do the labs. My destination is to catch up on the whole materials we learned these weeks.  I will complete the lab exercise 7 later today. l will go to the office hour to figure out my problems relating to link lists.

1 comment:

  1. Hi Miley,

    Regarding your question on the reference of lnk.back. In that case we assume that we have at least one node in the linked list and since we are appending an item, the item should be added at the end, not at the beginning of the list. Hope this helps!

    ReplyDelete