Class: DSA::BasicBinarySearchTreeNode

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

Overview

A basic binary search tree node

Direct Known Subclasses

RedBlackTreeNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ BasicBinarySearchTreeNode

Returns a new instance of BasicBinarySearchTreeNode.

Raises:

  • (KeyError)


5
6
7
8
9
10
11
12
# File 'lib/DSA/binary_search_tree.rb', line 5

def initialize(key, value)
  raise KeyError, 'Key cannot be nil' if key.nil?
  @key = key
  @value = value
  @parent = nil
  @left = nil
  @right = nil
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



4
5
6
# File 'lib/DSA/binary_search_tree.rb', line 4

def key
  @key
end

#leftObject

Returns the value of attribute left.



4
5
6
# File 'lib/DSA/binary_search_tree.rb', line 4

def left
  @left
end

#parentObject

Returns the value of attribute parent.



4
5
6
# File 'lib/DSA/binary_search_tree.rb', line 4

def parent
  @parent
end

#rightObject

Returns the value of attribute right.



4
5
6
# File 'lib/DSA/binary_search_tree.rb', line 4

def right
  @right
end

#valueObject

Returns the value of attribute value.



4
5
6
# File 'lib/DSA/binary_search_tree.rb', line 4

def value
  @value
end