Class: DSA::RedBlackTreeNode

Inherits:
BasicBinarySearchTreeNode show all
Defined in:
lib/DSA/binary_search_tree.rb

Constant Summary collapse

RED =
0
BLACK =
1

Instance Attribute Summary

Attributes inherited from BasicBinarySearchTreeNode

#key, #left, #parent, #right, #value

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ RedBlackTreeNode

Returns a new instance of RedBlackTreeNode.



424
425
426
427
# File 'lib/DSA/binary_search_tree.rb', line 424

def initialize(key, value)
  super(key, value)
  @color = RED
end

Instance Method Details

#black?Boolean

Returns:

  • (Boolean)


433
434
435
# File 'lib/DSA/binary_search_tree.rb', line 433

def black?
  @color == BLACK
end

#red?Boolean

Returns:

  • (Boolean)


429
430
431
# File 'lib/DSA/binary_search_tree.rb', line 429

def red?
  @color == RED
end

#set_black!Object



437
438
439
# File 'lib/DSA/binary_search_tree.rb', line 437

def set_black!
  @color = BLACK
end

#set_red!Object



441
442
443
# File 'lib/DSA/binary_search_tree.rb', line 441

def set_red!
  @color = RED
end