Class: AVLTree::BSTree

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-avl/bs_tree.rb

Direct Known Subclasses

AVLTree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ BSTree

Returns a new instance of BSTree.



6
7
8
# File 'lib/ruby-avl/bs_tree.rb', line 6

def initialize(root = nil)
  @root = root  
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/ruby-avl/bs_tree.rb', line 4

def root
  @root
end

Instance Method Details

#depth_of_treeObject

Starts the count of the depth at the root node.



28
29
30
# File 'lib/ruby-avl/bs_tree.rb', line 28

def depth_of_tree
  tree_depth(@root, 0)
end

#insert_item(item) ⇒ Object

Starts the search for the insertion at the root of the tree. Set the new root at the end if it has changed.



12
13
14
# File 'lib/ruby-avl/bs_tree.rb', line 12

def insert_item(item)
  @root = add_to_tree(item, @root)      
end

#number_of_nodesObject

Starts the count at the root node.



23
24
25
# File 'lib/ruby-avl/bs_tree.rb', line 23

def number_of_nodes
  node_count(@root)
end

#remove_item(item) ⇒ Object

Starts the search for the deletion at the root of the tree. Set the new root at the end if it has changed.



18
19
20
# File 'lib/ruby-avl/bs_tree.rb', line 18

def remove_item(item)
  @root = remove_from_tree(item, @root)
end