AVL Tree Program in C
AVL Tree Program in C
Lab program
Write a C program to insert node AVL tree
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* left;
struct node* right;
int ht;
};
1
// return the new node after rotation
return ptr;
}
inorder(root->left);
printf("%d ", root->data);
inorder(root->right);
}
int main()
{
int user_choice, data;
3
char user_continue;
while (1)
{
printf("\n\n------- AVL TREE --------\n");
printf("\n1. Insert");
printf("\n2. Inorder");
printf("\n3. EXIT");
printf("\n\nEnter Your Choice: ");
scanf("%d", &user_choice);
switch (user_choice)
{
case 1:
printf("\nEnter data: ");
scanf("%d", &data);
root = insert(root, data);
break;
case 2:
inorder(root);
break;
case 3:
printf("\n\tProgram Terminated\n");
return 0;
default:
printf("\n\tInvalid Choice\n");
}
}
return 0;
}
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
5
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT
1. Insert
2. Inorder
3. EXIT