17 std::unique_ptr<BSTNode<N>>
left;
18 std::unique_ptr<BSTNode<N>>
right;
21 std::unique_ptr<BSTNode<T>> root;
27 virtual void insert(
const T& value) {
28 std::unique_ptr<BSTNode<T>> node = std::make_unique<BSTNode<T>>();
38 virtual void display(
const bool& ascOrder =
true) {
50 virtual void remove() {
63 if (root ==
nullptr) {
64 root = std::move(node);
65 return std::move(root);
67 else if (data < root->data) {
74 return std::move(root);
86 std::cout << root->data << std::endl;
93 std::cout << root->data << std::endl;
108 else if(root->data == data){
111 else if(root->data > data){
114 else if(root->data < data){
121 virtual void removeHelper() {
This is a template class that represents a node/element in a Binary Search Tree.
Definition binary_tree.hpp:14
N data
Holds the data of a single node/element.
Definition binary_tree.hpp:16
std::unique_ptr< BSTNode< N > > right
Pointer to right child.
Definition binary_tree.hpp:18
std::unique_ptr< BSTNode< N > > left
Pointer to left child.
Definition binary_tree.hpp:17
This is a template class that represents a Binary Search Tree.
Definition binary_tree.hpp:8
virtual bool search(const T &data)
Searches for an element in the binary search tree.
Definition binary_tree.hpp:46
virtual bool searchHelper(std::unique_ptr< BSTNode< T > > &root, const T &data)
Helper to BSTree<T>::search()
Definition binary_tree.hpp:104
static void displayHelper(std::unique_ptr< BSTNode< T > > &root, const bool &ascendingOrder=true)
Helper to BSTree<T>::display()
Definition binary_tree.hpp:82
virtual void insert(const T &value)
Inserts a value into the binary search tree.
Definition binary_tree.hpp:27
virtual std::unique_ptr< BSTNode< T > > insertHelper(std::unique_ptr< BSTNode< T > > &root, std::unique_ptr< BSTNode< T > > &node)
Helper to BSTree<T>::insert()
Definition binary_tree.hpp:60
virtual void display(const bool &ascOrder=true)
Displays all the values in the binary search tree.
Definition binary_tree.hpp:38