2016年4月5日星期二

Week 8

-Linked List-
This week I learnt about linked list. This is a common method of storying data. In linked list, there is a class called Node. The data is connected by node; the first node will linked to the second node. Linked list is a very useful method.

As objects/ nodes with a value, those objects/nodes also have a reference to the other similar objects. The basic structure is:

(12)()---->(99)()---->(37)()--->()



The structure of node class is:

class LLNode:

     """Node to be used in linked list
     nxt: LLNode -- next node
                               None iff we're at end of list
     value: object --data for current node
     """
   
     def __init__(self, value, nxt=None):
          """(LLNnde, object LLNode) ->NoneType

          Creat LLNode (self) with data value and successor nxt.
          """
          self.value, self.nxt = value, nxt

There are also front and back in code, which helped us to find the front and end of the list.

I learnt many helpful code from class, such as:

                                  cur_node  = self. front
                                  cur_node = cur_node.nxt

By using the code I can add or delete the end node. Besides the last node, former last node, back, size, possibly front could all changed by using the method.



I noticed from the lab that when writing code of linked list, it is easy for me to make a copy of the list first, since if any node changed the following data could not be find.

没有评论:

发表评论