Class: NodeOfTree::Node
- Inherits:
-
Object
- Object
- NodeOfTree::Node
- Defined in:
- lib/BinarySearchk/node.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
Returns the value of attribute left.
-
#right ⇒ Object
Returns the value of attribute right.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(v) ⇒ Node
constructor
A new instance of Node.
- #insert(v) ⇒ Object
- #insert_left(v) ⇒ Object
- #insert_right(v) ⇒ Object
Constructor Details
#initialize(v) ⇒ Node
Returns a new instance of Node.
5 6 7 8 9 |
# File 'lib/BinarySearchk/node.rb', line 5 def initialize(v) @value = v @left = nil @right = nil end |
Instance Attribute Details
#left ⇒ Object
Returns the value of attribute left.
3 4 5 |
# File 'lib/BinarySearchk/node.rb', line 3 def left @left end |
#right ⇒ Object
Returns the value of attribute right.
3 4 5 |
# File 'lib/BinarySearchk/node.rb', line 3 def right @right end |
#value ⇒ Object
Returns the value of attribute value.
3 4 5 |
# File 'lib/BinarySearchk/node.rb', line 3 def value @value end |
Instance Method Details
#insert(v) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/BinarySearchk/node.rb', line 11 def insert(v) case value <=> v when 1 then insert_left(v) when -1 then insert_right(v) when 0 then end end |