|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
The Binary Search Tree class. More...
Classes | |
| struct | bst_node |
| A struct to represent a node in the Binary Search Tree. More... | |
Public Member Functions | |
| binary_search_tree () | |
| Construct a new Binary Search Tree object. More... | |
| bool | insert (T new_value) |
| Insert a new value into the BST. More... | |
| bool | remove (T rm_value) |
| Remove a specified value from the BST. More... | |
| bool | contains (T value) |
| Check if a value is in the BST. More... | |
| bool | find_min (T &ret_value) |
| Find the smallest value in the BST. More... | |
| bool | find_max (T &ret_value) |
| Find the largest value in the BST. More... | |
| std::size_t | size () |
| Get the number of values in the BST. More... | |
| std::vector< T > | get_elements_inorder () |
| Get all values of the BST in in-order order. More... | |
| std::vector< T > | get_elements_preorder () |
| Get all values of the BST in pre-order order. More... | |
| std::vector< T > | get_elements_postorder () |
| Get all values of the BST in post-order order. More... | |
Private Member Functions | |
| bool | find_max (std::unique_ptr< bst_node > &node, T &ret_value) |
| Recursive function to find the maximum value in the BST. More... | |
| bool | find_min (std::unique_ptr< bst_node > &node, T &ret_value) |
| Recursive function to find the minimum value in the BST. More... | |
| bool | insert (std::unique_ptr< bst_node > &node, T new_value) |
| Recursive function to insert a value into the BST. More... | |
| bool | remove (std::unique_ptr< bst_node > &parent, std::unique_ptr< bst_node > &node, T rm_value) |
| Recursive function to remove a value from the BST. More... | |
| bool | contains (std::unique_ptr< bst_node > &node, T value) |
| Recursive function to check if a value is in the BST. More... | |
| void | traverse_inorder (std::function< void(T)> callback, std::unique_ptr< bst_node > &node) |
| Recursive function to traverse the tree in in-order order. More... | |
| void | traverse_preorder (std::function< void(T)> callback, std::unique_ptr< bst_node > &node) |
| Recursive function to traverse the tree in pre-order order. More... | |
| void | traverse_postorder (std::function< void(T)> callback, std::unique_ptr< bst_node > &node) |
| Recursive function to traverse the tree in post-order order. More... | |
Private Attributes | |
| std::unique_ptr< bst_node > | root_ |
| std::size_t | size_ = 0 |
The Binary Search Tree class.
| T | The type of the binary search tree key. |
|
inline |
Construct a new Binary Search Tree object.
|
inlineprivate |
Recursive function to check if a value is in the BST.
| node | The node to search from. |
| value | The value to find. |
|
inline |
|
inlineprivate |
Recursive function to find the maximum value in the BST.
| node | The node to search from. |
| ret_value | Variable to hold the maximum value. |
|
inline |
|
inlineprivate |
Recursive function to find the minimum value in the BST.
| node | The node to search from. |
| ret_value | Variable to hold the minimum value. |
|
inline |
|
inline |
Get all values of the BST in in-order order.
|
inline |
Get all values of the BST in post-order order.
|
inline |
Get all values of the BST in pre-order order.
|
inlineprivate |
Recursive function to insert a value into the BST.
| node | The node to search from. |
| new_value | The value to insert. |
|
inline |
Insert a new value into the BST.
| new_value | The value to insert into the BST. |
|
inlineprivate |
Recursive function to remove a value from the BST.
| parent | The parent node of node. |
| node | The node to search from. |
| rm_value | The value to remove. |
|
inline |
|
inline |
|
inlineprivate |
Recursive function to traverse the tree in in-order order.
| callback | Function that is called when a value needs to processed. |
| node | The node to traverse from. |
|
inlineprivate |
Recursive function to traverse the tree in post-order order.
| callback | Function that is called when a value needs to processed. |
| node | The node to traverse from. |
|
inlineprivate |
Recursive function to traverse the tree in pre-order order.
| callback | Function that is called when a value needs to processed. |
| node | The node to traverse from. |
|
private |
Pointer to the root of the BST.
|
private |
Number of elements/nodes in the BST.