Day 0 (Nodes)

An individual node contains two type of things: data it stores and links to other nodes. 

The link or links within the nodes are sometimes referred as pointers (because they point to other nodes). 

If these links are null, it means that you have reached the end of the particular node or link path you were previously following.

Nodes can be orphaned if there are no existing links to them.

Python implementation (Using OOP):

class Node:
  def __init__(self, value, link_node=None):
    self.value = value
    self.link_node = link_node
    
  def set_link_node(self, link_node):
    self.link_node = link_node
    
  def get_link_node(self):
    return self.link_node
  
  def get_value(self):
    return self.value

# Add your code below:
yacko = Node("likes to yak")
wacko = Node("has a penchant for hoarding snacks")
dot = Node("enjoys spending time in movie lots")

yacko.set_link_node(dot)
dot.set_link_node(wacko)
dots_data = yacko.get_link_node().get_value()
wackos_data = dot.get_link_node().get_value()
print(dots_data)
print(wackos_data)

Above are some examples regard to Nodes. 

上一篇:学习笔记 8 Day(函数)


下一篇:学习笔记 -- Day 7 (循环语句)