13 insert_iterative(this->p_head.get(),
val);
19 std::vector<Node<T> *>
path;
44 for (
auto it = path.rbegin(); it != path.rend(); ++it)
46 Node<T> *ancestor = *it;
54template <
typename T>
inline std::unique_ptr<Node<T>> BST<T>::remove_impl(std::unique_ptr<Node<T>> node,
const T &val)
59 if (val < node->m_data)
61 node->p_left = remove_impl(std::move(node->p_left), val);
63 else if (val > node->m_data)
65 node->p_right = remove_impl(std::move(node->p_right), val);
70 return std::move(node->p_right);
73 return std::move(node->p_left);
75 Node<T> *temp = node->p_right.get();
78 temp = temp->p_left.get();
81 node->m_data = temp->m_data;
83 node->p_right = remove_impl(std::move(node->p_right), temp->m_data);
105 this->p_head = remove_impl(std::move(this->p_head),
val);
112 throw std::runtime_error(
"Empty");
122 throw std::runtime_error(
"Empty");
157 throw std::runtime_error(
"No successor");
161 throw std::runtime_error(
"Value not found");
193 throw std::runtime_error(
"No predecessor");
196 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
static std::unique_ptr< Node< T > > make_node(const T &val)
int get_height_val() const
void set_left(std::unique_ptr< Node< T > > node)
const T & get_data() const
Node< T > * get_right() const
void set_right(std::unique_ptr< Node< T > > node)
Node< T > * get_left() const
void set_height_val(int h)