A generic binary search tree implementation.
More...
#include <cassert>
#include <functional>
#include <iostream>
#include <memory>
#include <vector>
◆ test_contains()
| static void test_contains |
( |
| ) |
|
|
static |
Function for testing contains().
- Returns
void
The Binary Search Tree class.
Definition: binary_search_tree2.cpp:19
bool insert(std::unique_ptr< bst_node > &node, T new_value)
Recursive function to insert a value into the BST.
Definition: binary_search_tree2.cpp:89
bool contains(std::unique_ptr< bst_node > &node, T value)
Recursive function to check if a value is in the BST.
Definition: binary_search_tree2.cpp:176
◆ test_find_max()
| static void test_find_max |
( |
| ) |
|
|
static |
Function for testing find_max().
- Returns
void
bool find_max(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the maximum value in the BST.
Definition: binary_search_tree2.cpp:52
◆ test_find_min()
| static void test_find_min |
( |
| ) |
|
|
static |
Function for testing find_min().
- Returns
void
bool find_min(std::unique_ptr< bst_node > &node, T &ret_value)
Recursive function to find the minimum value in the BST.
Definition: binary_search_tree2.cpp:70
◆ test_get_elements_inorder()
| static void test_get_elements_inorder |
( |
| ) |
|
|
static |
Function for testing get_elements_inorder().
- Returns
void
498 std::cout <<
"Testing BST get_elements_inorder...";
508 assert(actual == expected);
std::vector< T > get_elements_inorder()
Get all values of the BST in in-order order.
Definition: binary_search_tree2.cpp:320
◆ test_get_elements_postorder()
| static void test_get_elements_postorder |
( |
| ) |
|
|
static |
Function for testing get_elements_postorder().
- Returns
void
540 std::cout <<
"Testing BST get_elements_postorder...";
550 assert(actual == expected);
std::vector< T > get_elements_postorder()
Get all values of the BST in post-order order.
Definition: binary_search_tree2.cpp:344
◆ test_get_elements_preorder()
| static void test_get_elements_preorder |
( |
| ) |
|
|
static |
Function for testing get_elements_preorder().
- Returns
void
519 std::cout <<
"Testing BST get_elements_preorder...";
529 assert(actual == expected);
std::vector< T > get_elements_preorder()
Get all values of the BST in pre-order order.
Definition: binary_search_tree2.cpp:332
◆ test_insert()
| static void test_insert |
( |
| ) |
|
|
static |
Function for testing insert().
- Returns
void
361 bool res = tree.
insert(5);
368 assert(tree.
size() == 1);
377 assert(tree.
size() == 4);
379 bool fail_res = tree.
insert(4);
381 assert(tree.
size() == 4);
std::size_t size()
Get the number of values in the BST.
Definition: binary_search_tree2.cpp:313
◆ test_remove()
| static void test_remove |
( |
| ) |
|
|
static |
Function for testing remove().
- Returns
void
400 bool res = tree.
remove(5);
407 assert(tree.
size() == 3);
413 assert(tree.
size() == 0);
416 bool fail_res = tree.
remove(5);
418 assert(tree.
size() == 0);
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.
Definition: binary_search_tree2.cpp:124