HolyAVLTree

This commit is contained in:
e2hang
2025-08-19 18:01:45 +08:00
parent 6a8b2b7cb7
commit 03d0c1b039
6 changed files with 407 additions and 1 deletions

View File

@@ -0,0 +1,97 @@
#include <iostream>
#include "avl.h"
using namespace std;
int main() {
AVL<int> tree;
tree.insert(10);
tree.display();
tree.outputTree(10);
tree.insert(20);
tree.display();
tree.outputTree(20);
tree.insert(30);
tree.display();
tree.outputTree(30);
tree.insert(100);
tree.display();
tree.outputTree(100);
tree.insert(50);
tree.display();
tree.outputTree(50);
tree.insert(70);
tree.display();
tree.outputTree(70);
tree.insert(80);
tree.display();
tree.outputTree(80);
tree.insert(60);
tree.display();
tree.outputTree(60);
cout << endl << endl << endl;
cout << "To erase: " << endl;
tree.erase(60);
tree.display();
tree.outputTree(100);
tree.erase(100);
tree.display();
tree.outputTree(80);
return 0;
}
/*
OutputTree写的不好
Root is: 10
10
10
Root is: 10
10 20
10
20
Root is: 20
10 20 30
20
10 30
Root is: 20
10 20 30 100
20
10 30
100
Root is: 20
10 20 30 50 100
20
10 50
Root is: 50
10 20 30 50 70 100
50
20 100
10 30 70
Root is: 50
10 20 30 50 70 80 100
50
20 80
Root is: 50
10 20 30 50 60 70 80 100
50
20 80
10 30 70 100
60
To erase:
Root is: 50
10 20 30 50 70 80 100
50
20 80
10 30 70 100
Root is: 50
10 20 30 50 70 80
50
20 80
*/