This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <stack> | |
template<typename KeyType, typename Comparator = std::less<KeyType> > | |
class binary_search_tree{ | |
protected: | |
Comparator isLessThan; | |
class bst_node{ | |
public: | |
KeyType key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "bst_tree.hpp" | |
template<typename KeyType, typename Comparator = std::less<KeyType> > | |
class avl_tree : public binary_search_tree<KeyType, Comparator>{ | |
protected: | |
class avl_node : public binary_search_tree<KeyType, Comparator>::bst_node{ | |
public: | |
avl_node(KeyType key): | |
binary_search_tree<KeyType, Comparator>::bst_node(key),height(1){} | |
int height; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main(){ | |
binary_search_tree<int> bstTree; | |
avl_tree<int> avlTree; | |
bstTree.insert(5); | |
bstTree.insert(4); | |
bstTree.insert(6); | |
bstTree.insert(12); | |
bstTree.insert(1); | |
bstTree.insert(3); |