Class: BinarySearch::RedBlackTree::Node
- Inherits:
-
Struct
- Object
- Struct
- BinarySearch::RedBlackTree::Node
- Defined in:
- lib/binary_search/red_black_tree/node.rb
Overview
Represents a node in the Red-Black Tree
A node contains a key, color, references to its left and right children, and a reference to its parent. The color is used to maintain the balance properties of the Red-Black Tree.
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#key ⇒ Object
Returns the value of attribute key.
-
#left ⇒ Object
Returns the value of attribute left.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#right ⇒ Object
Returns the value of attribute right.
Instance Method Summary collapse
-
#black? ⇒ Boolean
Checks if the node is black.
-
#initialize(key, color = :red, left = nil, right = nil, parent = nil) ⇒ Node
constructor
Creates a new Node.
-
#red? ⇒ Boolean
Checks if the node is red.
Constructor Details
#initialize(key, color = :red, left = nil, right = nil, parent = nil) ⇒ Node
Creates a new Node
18 19 20 |
# File 'lib/binary_search/red_black_tree/node.rb', line 18 def initialize(key, color = :red, left = nil, right = nil, parent = nil) super(key, color, left, right, parent) end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color
10 11 12 |
# File 'lib/binary_search/red_black_tree/node.rb', line 10 def color @color end |
#key ⇒ Object
Returns the value of attribute key
10 11 12 |
# File 'lib/binary_search/red_black_tree/node.rb', line 10 def key @key end |
#left ⇒ Object
Returns the value of attribute left
10 11 12 |
# File 'lib/binary_search/red_black_tree/node.rb', line 10 def left @left end |
#parent ⇒ Object
Returns the value of attribute parent
10 11 12 |
# File 'lib/binary_search/red_black_tree/node.rb', line 10 def parent @parent end |
#right ⇒ Object
Returns the value of attribute right
10 11 12 |
# File 'lib/binary_search/red_black_tree/node.rb', line 10 def right @right end |
Instance Method Details
#black? ⇒ Boolean
Checks if the node is black
25 26 27 |
# File 'lib/binary_search/red_black_tree/node.rb', line 25 def black? color == :black end |
#red? ⇒ Boolean
Checks if the node is red
32 33 34 |
# File 'lib/binary_search/red_black_tree/node.rb', line 32 def red? color == :red end |