// include guard #ifndef AVLC_H #define AVLC_H #include #include class AVLCommands; class BSTNode { public: BSTNode(int key); BSTNode(int key, std::weak_ptr parent); bool IsLeaf() const; bool IsMissingChild() const; bool HasLeftChild() const; bool HasRightChild() const; void DeleteChild(std::shared_ptr v); void ReplaceChild(std::shared_ptr v, std::shared_ptr u); private: int key_; std::weak_ptr parent_; std::shared_ptr left_; std::shared_ptr right_; int height_; int balance_; //friend BST; friend AVLCommands; }; // class BSTNode class AVLCommands { public: AVLCommands(); void Insert(int key); bool Delete(int key); bool Find(int key) const; std::string JSON() const; size_t size() const; bool empty() const; int DeleteMin(); void printTree(); private: int max(int a, int b); int height(std::shared_ptr currentNode); void balance(std::shared_ptr currentNode); std::shared_ptr rightRotate(std::shared_ptr); std::shared_ptr leftRotate(std::shared_ptr); void DeleteLeaf(std::shared_ptr currentNode); int DeleteMin(std::shared_ptr currentNode); void printTree(std::shared_ptr currentNode); std::shared_ptr root_; size_t size_; }; // class BST #endif