Avl Tree Insertion
Avl Tree Insertion
#include <bits/stdc++.h>
using namespace std;
struct Node {
int element;
struct Node *left, *right;
int height;
};
x->right = y;
y->left = T2;
return x;
}
y->left = x;
x->right = T2;
x->height = max(height(x->left), height(x->right)) + 1;
y->height = max(height(y->left), height(y->right)) + 1;
return y;
}
return node;
}
int main() {
Node *root = NULL;
int x, n, option;
cout << "1. Create AVL Tree\n";
cout << "2. End Program\n";
cout << "Enter your choice ";
cin >> option;
switch (option) {
case 1:
cout << "\nEnter no. of elements : ";
cin >> n;
root = NULL;
for (int i = 0; i < n; i++) {
cout << "Enter element of tree ";
cin >> x;
root = insert(root, x);
}
cout << "\nPreorder sequence:\n";
preOrder(root);
break;
}
return 0;
}