#ifndef HOMEWORK_NO_SUBMISSION_BSTREE_H
#define HOMEWORK_NO_SUBMISSION_BSTREE_H
#include <memory>
#include <iostream>
#include <iostream>
#include <memory>
template<typename T>
struct Node {
T value;
std::unique_ptr<Node> left, right;
explicit Node(T val) : value(val), left(nullptr), right(nullptr) {}
};
template<typename T>
class BST {
public:
BST() : _root(nullptr) {}
public:
void print_inorder();
void print_preorder();
void print_postorder();
public:
void insert(T && value){
insert_data(std::move(value));
}
void insert(T & value){
insert_data(value);
}
public:
T find(const T& value) const {
auto val = find_helper(_root.get(), value);
return val->value;
}
public:
void remove(const T &data) {
remove_helper(_root, data) ;
}
public:
void clear() {
clear_helper(_root);
}
public:
const Node<T> * get_root() const { return _root.get(); }
private:
std::unique_ptr<Node<T>> _root;
private:
void print_helper(Node<T>*, char c ='i');
void insert_data(T && val);
void insert_data(T & val);
const Node<T> * find_helper(const Node<T> * node,const T& value) const ;
T get_min_value(const std::unique_ptr<Node<T>>& node);
void remove_helper(std::unique_ptr<Node<T>> & , const T & data);
private:
void clear_helper(std::unique_ptr<Node<T>>& node);
};
#endif //HOMEWORK_NO_SUBMISSION_BSTREE_H
#include "BSTree_impl.h"