12 this->p_head = this->make_node(
val);
15 insert_iterative(this->p_head,
val);
28 curr->p_left = this->make_node(
val);
37 curr->p_right = this->make_node(val);
45template <
typename T>
void BST<T>::remove_impl(
const T &val)
53 Node<T> **link = &this->p_head;
54 Node<T> *node = this->p_head;
58 if (val < node->m_data)
63 else if (val > node->m_data)
65 link = &node->p_right;
72 *link = node->p_right;
73 this->m_pool.deallocate(node);
79 this->m_pool.deallocate(node);
83 Node<T> *succ = node->p_right;
84 Node<T> **succ_link = &node->p_right;
87 succ_link = &succ->p_left;
91 node->m_data = succ->m_data;
92 *succ_link = succ->p_right;
93 this->m_pool.deallocate(succ);
120 throw std::runtime_error(
"Empty");
130 throw std::runtime_error(
"Empty");
165 throw std::runtime_error(
"No successor");
169 throw std::runtime_error(
"Value not found");
193 while (
temp->p_right)
201 throw std::runtime_error(
"No predecessor");
204 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