Java教程

Day 0 (Nodes)

本文主要是介绍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. 

这篇关于Day 0 (Nodes)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!