Algorithmen_Datenstrukturen/Uebung 2/Uebung2_3/main.cpp

43 lines
1.1 KiB
C++

#include "avlNode.h"
#include <iostream>
#include <string>
int main() {
AvlNode *root = new AvlNode(10);
// always give the root, as it could be changed with any insertion (in
// comparison to BST!)
root = root->insert(15);
root = root->insert(5);
root = root->insert(8);
root = root->insert(3);
root = root->insert(9);
root = root->insert(16);
root = root->insert(17);
root = root->deleteItem(10);
for (int i = 20; i <= 50; i++) {
root = root->insert(i);
}
// root = root->deleteItem(5);
/* -- Scenarion 1 - rightRotation -- */
// root = root->insert(2);
/* -- Scenarion 2 - leftRotation -- */
// root = root->insert(17);
// root = root->insert(19);
/* -- Scenarion 3 - rightRotation, then leftRotation -- */
// root = root->insert(17);
// root = root->insert(16);
/* -- Scenarion 4 - leftRotation, then rightRotattion -- */
// root = root->insert(17);
// root = root->insert(6);
// root = root->insert(7);
std::cout << root->printPreorder();
std::cout << "Perfectly balanced! As all things should be!\n";
return 0;
}