Class: AVLTree::BSTree
- Inherits:
-
Object
- Object
- AVLTree::BSTree
- Defined in:
- lib/ruby-avl/bs_tree.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#depth_of_tree ⇒ Object
Starts the count of the depth at the root node.
-
#initialize(root = nil) ⇒ BSTree
constructor
A new instance of BSTree.
-
#insert_item(item) ⇒ Object
Starts the search for the insertion at the root of the tree.
-
#number_of_nodes ⇒ Object
Starts the count at the root node.
-
#remove_item(item) ⇒ Object
Starts the search for the deletion at the root of the tree.
Constructor Details
Instance Attribute Details
#root ⇒ Object (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_tree ⇒ Object
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_nodes ⇒ Object
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 |