Class: DcUtil::BinaryNode

Inherits:
Node
  • Object
show all
Defined in:
lib/dc_util/binary_node.rb

Instance Attribute Summary

Attributes inherited from Node

#children, #data, #parent

Instance Method Summary collapse

Methods inherited from Node

#add, bfs, #bfs, bfs_non_recursive, dfs, #dfs, #initialize, #leaves, #parents, #tree_size

Constructor Details

This class inherits a constructor from DcUtil::Node

Instance Method Details

#leftObject

returns left child



4
5
6
# File 'lib/dc_util/binary_node.rb', line 4

def left
  children[0]
end

#left=(node) ⇒ Object

set left child

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/dc_util/binary_node.rb', line 14

def left=(node)
  raise ArgumentError.new("not a valid node class") unless node.kind_of? self.class
  children[0] = node
  node.parent = self
end

#rightObject

returns right child



9
10
11
# File 'lib/dc_util/binary_node.rb', line 9

def right
  children[1]
end

#right=(node) ⇒ Object

set right child

Raises:

  • (ArgumentError)


21
22
23
24
25
# File 'lib/dc_util/binary_node.rb', line 21

def right=(node)
  raise ArgumentError.new("not a valid node class") unless node.kind_of? self.class
  children[1] = node
  node.parent = self
end