| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- #include <iostream>
- #include "AVLCommands.h"
- #include "BST.h"
- // AVL explanation:
- // http://www.btechsmartclass.com/DS/U5_T2.html
- // combination of geeksforgeeks AVL insert and delete code
- // https://www.geeksforgeeks.org/avl-tree-set-2-deletion/
- // written for C
- // An AVL tree node struct that is probably useless to me
- struct Node { // already have a struct inside BST...
- // maybe no pointers in here...
- // but then why bother with a struct :/
- int key;
- //std::shared_ptr<BSTNode> currentNode = root_;
- //struct Node *left;
- //struct Node *right;
- int height;
- };
- // constructor: builds an AVL tree from BST tree bst
- AVLCommands::AVLCommands() {
- class BST bst(); //
- } // initialize BST with root null and sized 0
- void AVLCommands::Insert(int key) {
- // normal BST insertion
- bst.Insert(key);
- std::shared_ptr<BSTNode> currentNode = root_;
- // update height of this ancestor node
- // height = 1 + max(height(node->left), height(node->right))
- // check if the tree is unbalanced by checking
- // ancestor balance factor
- // if unbalanced
- // left-left
- // right-right
- // left-right
- // right-left
- }
|