2#include "../include/cppx.h"
10 this->p_head = this->make_node(
val);
13 insert_iterative(this->p_head,
val);
26 curr->p_left = this->make_node(
val);
35 curr->p_right = this->make_node(val);
43template <
typename T>
void BST<T>::remove_impl(
const T &val)
51 Node<T> **link = &this->p_head;
52 Node<T> *node = this->p_head;
56 if (val < node->m_data)
61 else if (val > node->m_data)
63 link = &node->p_right;
70 *link = node->p_right;
71 this->m_pool.deallocate(node);
77 this->m_pool.deallocate(node);
81 Node<T> *succ = node->p_right;
82 Node<T> **succ_link = &node->p_right;
85 succ_link = &succ->p_left;
89 node->m_data = succ->m_data;
90 *succ_link = succ->p_right;
91 this->m_pool.deallocate(succ);
118 throw std::runtime_error(
"Empty");
128 throw std::runtime_error(
"Empty");
163 throw std::runtime_error(
"No successor");
167 throw std::runtime_error(
"Value not found");
191 while (
temp->p_right)
199 throw std::runtime_error(
"No predecessor");
202 throw std::runtime_error(
"Value not found");
T get_predecessor(const T &val) const
virtual void insert(const T &val)
T get_successor(const T &val) const
virtual void remove(const T &val)
bool contains(const T &val) const