IMPLEMENTATION OF SINGLY LINKED LIST

AIM:

To write a c program to implement singly linked list

ALGORITHM:

Step 1: Create a list of element one linked to the other using create function Step 2: To insert any new element to the list, we have to get the position where to insert it and do the insertion using insert function Step 3: After create the list if we have to delete any element we can do it by getting the position to be deleted Step 4: Display the contents using display function Step 5: Exit the program

PROGRAM CODING: #include<stdio.h> #include<stdlib.h> #include<conio.h> int i; struct node; typedef struct node *list; typedef struct node *pos; struct node { int e; pos next; }; void deletelist(list L) { pos p,tmp; p=L->next; L->next=NULL; while(p!=NULL) { tmp=p->next;

free(p); p=tmp; } } list makeempty(list L) { if(L!=NULL) deletelist(L); L=malloc(sizeof(struct node)); L->next=NULL; return L; } int isempty(list L) { return L->next==NULL; } int islast(pos p) { return p->next==NULL; } pos find(int x,list L) { pos p; p=L->next;

while(p!=NULL&&p->e!=x) p=p->next; return p; } void insert(int x,pos p) { pos tmpcell; tmpcell=malloc(sizeof(struct node)); tmpcell->e=x; tmpcell->next=p->next; p->next=tmpcell; } pos header(list L) {return L; } pos advance(pos p) {return p->next; } int retrieve(pos p) {return p->e; } void printlist(const list L) {pos p=header(L); do

{ p=advance(p); printf("%d",retrieve(p)); }while(!islast(p)); printf("\n"); } int main() {list L; pos p; int i; clrscr(); L=makeempty(L); p=header(L); for(i=0;i<10;i++) { insert(i,p); printlist(L); p=advance(p); } printf("Enter the number you wish to find"); scanf("%d" ,&i); if(find(i,L)!=NULL) printf("Element found"); else

p=header(L). return 0. if(isempty(L)) printf("\nDeletion successfully completed"). deletelist(L). getch(). } OUTPUT: 0 01 012 0123 01234 012345 0123456 01234567 012345678 0123456789 Enter the number you wish to find:2 Element found Deletion successfully completed .printf("Element not found").

RESULT: Thus the c program for implementation of linked list was executed and the output was verified. we have to get the position where to insert it and do the insertion using insert function Step 3: After create the list if we have to delete any element we can do it by getting the position to be deleted Step 4: Display the contents using display function Step 5: Exit the program . Ex.No: Date: IMPLEMENTATION OF DOUBLY LINKED LIST AIM: To write a c program to implement doubly linked list ALGORITHM: Step 1: Create a list of element one linked to the other using create function Step 2: To insert any new element to the list.

typedef ptrtonode position. .PROGRAM CODING: #include<stdio. typedef int elementtype. list makeempty(list L) { if(L!=NULL) deletelist(L). position Next.h> #include<stdlib.h> typedef struct node *ptrtonode. struct node { elementtype element. typedef ptrtonode list.Prev. }. L=malloc(sizeof(struct node)).

if(L==NULL) printf("Out of Memory!"). L->Next=NULL. return P. L->Prev=NULL. } void delete(elementtype X. } int isempty(list L) { return (L->Next==NULL && L->Prev==NULL).list L) . while(P!=NULL && P->element!=X) P=P->Next.list L) { position P. } position find(elementtype X.list L) { return P->Next==NULL. return L. P=L->Next. } int islast(position P.

P=find(X. } int deletelist(list L) { position P. } void insert(elementtype X. tempcell->element=X.tmp.{ position P. tempcell=malloc(sizeof(struct node)). tempcell->Next=P->Next. P->Next->Prev=P->Prev. if(tempcell==NULL) printf("Out of space!!!"). .list L.L). P->Prev->Next=P->Next. tempcell->Prev=P.position P) { position tempcell. P->Next=tempcell. P=L->Next. P->Next->Prev=tempcell. free(P).

while(P!=NULL) { tmp=P->Next. } position advance(position P) { return P->Next. . free(P). P=tmp. } position first(list L) { return L->Next.L->Next=NULL. L->Prev=NULL. } return 0. } position header(list L) { return L.

printf("%d". } while(!islast(P.L)). } void printlist(const list L) { position P=header(L).} elementtype retrieve(position P) { return P->element. printf("\n"). if(isempty(L)) printf("Empty List\n"). } } main() . else { do { P=advance(P).retrieve(P)).

P). printlist(L). } for(i=0.i<10.i++) { insert(i. . printf("Finished deletion\n"). printlist(L).L. P= advance(P). clrscr(). P=header(L). L=makeempty(NULL).{ list L. printf("Enter the Number you want to find:\t"). position P. int i. for(i=0.i+=2) delete(i.&i). else printf("element not found").L). printlist(L). if(find(i. scanf("%d".i<10.L)!=NULL) printf("Element found").

return 0. getch().deletelist(L). } OUTPUT: Empty list 0 01 012 0123 01234 012345 0123456 01234567 012345678 0123456789 Finished Deletion 13579 Enter the number you want to find:1 Element found RESULT: Thus the c program for implementation of linked list was executed and .

No: Date: IMPLEMENTATION OF POLYNOMIAL ADDITION AIM: To write a c program to illustrate polynomial addition ALGORITHM: STEP 1: Create a function. STEP 5: Print the details STEP 6: Exit the program . Check for the greater number between numbers having the same number.the output was verified. Get the input from user of the coefficients and the power and create node for it STEP 2: Continue step1 until the user press a key other than y or Y Step 3: Create a function show to display the details STEP 4: Create a function named poly. Ex.

*poly=NULL. struct link *next. void creat(struct link *node) { char ch.h> struct link { int coeff. .h> #include<conio. do { printf("\n Enter Coef:\t") .*poly2=NULL. struct link *poly1=NULL. scanf("%d".PROGRAM CODING: #include<stdio.&node->coeff).pow.h> #include<malloc. }.

node->coeff.printf(" Enter Power :\t "). scanf("%d".struct link *poly) { while((poly1 ->next) && (poly2->next)) { . node=node->next. ch=getch(). if(node->next!=NULL) printf(" +"). printf("\n\t\t Continue (y/n)\n\n").struct link *poly2. node->next=NULL. } void show(struct link *node) { while(node->next!=NULL) { printf(" %dx^%d".&node->pow). node->next=(struct link *)malloc(sizeof(struct link)) .node->pow). node=node->next. } } void polyadd(struct link *poly1. } while(ch=='y'||ch=='Y').

poly1=poly1->next. poly1=poly1->next. } else if(poly1->pow < poly2->pow) { poly->pow=poly2->pow. poly2=poly2->next. poly->coeff=poly2->coeff. poly2=poly2->next. poly->coeff=poly1->coeff. poly=poly->next. poly->next=NULL. } else { poly->pow=poly1->pow. poly->coeff=(poly1->coeff)+(poly2->coeff).if(poly1->pow > poly2->pow) { poly->pow=poly1->pow. } poly->next=(struct link *)malloc(sizeof(struct link)). } while(poly1->next||poly2->next) .

} poly->next=(struct link *)malloc(sizeof(struct link)). } } void main() { char ch. poly->next=NULL. poly1=poly1->next. } if(poly2->next) { poly->pow=poly2->pow. do { . poly->coeff=poly2->coeff. poly=poly->next. clrscr(). poly2=poly2->next. poly->coeff=poly1->coeff.{ if(poly1->next) { poly->pow=poly1->pow.

poly1=(struct link*)malloc(sizeof(struct link)). ch=getch().poly2.\n\n"). printf("\n 2nd No. show(poly2)."). printf("\n 1st No. poly2=(struct link*)malloc(sizeof(struct link)). } OUTPUT Enter 1st No. show(poly). printf("\n\n\t\t Add more number(y/n)"). printf("\n\t\t\t\t Enter 1st No. printf("\n\n\t Added Polynomial: \n f(x)="). } while(ch=='y'||ch=='Y'). Enter Coef: 2 . show(poly1).poly). creat(poly1). poly=(struct link*)malloc(sizeof(struct link)). printf("\n\t\t\t\tEnter 2nd No.\n\n"). creat(poly2)."). polyadd(poly1.

Enter Coef: Enter Power : 52 3 Continue (y/n) Enter Coef: Enter Power : 10 2 Continue (y/n) 1st No.Enter Power : 3 Continue (y/n) Enter Coef: Enter Power : 52 2 Continue (y/n) Enter 2nd No. 52x^3 + 10x^2 Added Polynomial: f(x)= 54x^3 + 62x^2 Add more number(y/n) . 2x^3 + 52x^2 2nd No.

Check for the priority of operators while pushing STEP 5: If the element to be pushed has higher priority than the .RESULT Thus the program for Addition of polynomial is executed and output is verified Ex.No: Date: INFIX TO POSTFIX CONVERSION AIM: To write a c program to convert infix expression to postfix expression ALGORITHM: STEP 1: Start STEP 2: Check the conditions whether the stack is empty or not to insert an element STEP 3: If the stack is not full push the element onto the stack STEP 4: Repeat the Step 3 until delimiter or end appears.

j++) { . char infix[20].h> #include<conio.l=0.(x=infix[j])!='\0'. int priority(char). infixtopostfix(). printf("enter the expression"). } void infixtopostfix() { int j.postfix). int top=-1.h> #define operand(x) (x>='a'&&x<='z'||x>='A'&&x<='Z') void infixtopostfix().postfix[20].infix).stack[20]. char x.y. printf("%s".operator in the stack push the element onto the stack STEP 6: ELSE pop out the two contents at the top from the top and apply the operator STEP 7: Execute the program STEP 8: Stop PROGRAM CODING: #include<stdio. scanf("%s". void push(char). for(j=0. void main() { clrscr(). getch(). char pop().

top--. n=stack[top]. else if(x==')') { while((y=pop())!='(') postfix[l++]=y. } } while(top>=0) postfix[l++]=pop(). return(n). return y. else if(x=='(') push(x). y=(x=='('?3:x=='*'?2:x=='/'?2:x=='+'?1:x=='-'?1:-1). } else { while(priority(stack[top])>=priority(x)&&stack[top]! ='(') postfix[l++]=pop().if(operand(x)) postfix[l++]=x. } OUTPUT: Enter the expression a+b-c/d . push(x). } char pop() { char n. } void push(char n) { stack[++top]=n. } int priority(char x) { int y.

ab+cd/- RESULT: Thus the conversion from infix expression to postfix was executed and the output was verified. Ex.No: Date: IMPLEMENTATION OF DOUBLE ENDED QUEUE AIM: To write a program to implement double ended queue ALGORITHM: STEP 1: Create a queue and check whether the queue is empty or not STEP 2: Write a function to insert element in the rear end STEP 3: Create a function to insert the element in the front end .

}deque.ch. . int). void create(deque *). void insert_front(deque *. void main() { int x. int delete_rear(deque *. void display(deque *). int item[SIZE]. int).h> #include<conio. int).STEP 4: Create two functions to delete the element from queue from both rear and front end Step 5: Display the result STEP 6: Execute the program STEP 7: Stop PROGRAM CODING: #include<stdio. int). int delete_front(deque *.h> #define SIZE 20 typedef struct dq_t { int front. void insert_rear(deque *.data.rear.

deque DQ. printf(“\n\t\t 3: delete from front end”).rear >= SIZE) { printf(“\n Deque is full at rear end”). continue. } else { printf(“\n Enter element to be added at rear end :”). insert_rear(&DQ. } .&ch). printf(“\n\t\t 1: insert at rear end”). printf(“\n Elements in a deque are :”). printf(“\n\t\t Enter choice :”). scanf(“%d”.&data). printf(“\n\t\t 5: exit. printf(“\n\t\t 4: delete from rear end”).data). continue. switch(ch) { case 1: if (DQ. do { printf(“\n\t\t Menu”). scanf(“%d”. display(&DQ). “). } case 2: if (DQ. create(&DQ). continue. printf(“\n\t\t Program shows working of double ended queue”). clrscr().front <=0) { printf(“\n Deque is full at front end”). printf(“\n\t\t 2: insert at front end”).

continue. display(&DQ).else { printf(“\n Enter element to be added at front end :”). } case 3: x = delete_front(&DQ. } case 4: x = delete_rear(&DQ. return. display(&DQ). if (DQ. continue.data).data). if (DQ.&data). } else { printf(“\n Elements in a deque are :”). getch(). } else { printf(“\n Elements in a deque are :”). printf(“\n Elements in a deque are :”).rear==0) { continue.front==0) { continue. } case 5: printf(“\n finish”). display(&DQ). } }while(ch!=5). insert_front(&DQ. scanf(“%d”. } .data). continue.

printf(“\n Deque is empty (front end)”). int data) { if ((DQ->front == 0) &&(DQ->rear == 0)) { DQ->item[DQ->rear] = data. } void insert_rear(deque *DQ. DQ->front = DQ->front +1. int data) { if ((DQ->front == 0) && (DQ->rear == 0)) { printf(“\n Underflow”). DQ->rear = 0. .void create(deque *DQ) { DQ->front=0. } return data. } else { DQ->item[DQ->rear] = data. printf(“\n Element %d is deleted from front :”. DQ->rear =0. } } int delete_front(deque *DQ. return(0). } else { data = DQ->item[DQ->front]. DQ->rear = DQ->rear +1. DQ->rear = DQ->rear +1. } if (DQ->front==DQ->rear) { DQ->front =0.data).

} if (DQ->front==DQ->rear) { DQ->front =0. int data) { if(DQ->front > 0) { DQ->front = DQ->front-1. } else { DQ->rear = DQ->rear -1. } return data.x++) { .data).} void insert_front(deque *DQ. printf(“\n Element %d is deleted from rear:”.xrear. DQ->item[DQ->front] = data. } } int delete_rear(deque *DQ. for(x=DQ->front. printf(“\n Deque is empty(rear end)”). DQ->rear = 0. data = DQ->item[DQ->rear]. } void display(deque *DQ) { int x. return(0). int data) { if (DQ->rear == 0) { printf(“\n Underflow”).

} OUTPUT: Program shows working of double ended queue Menu 1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit. } printf(“\n\n”). Enter choice :1 Enter element to be added at rear end :33 Elements in a deque are :11 22 33 Menu . Enter choice :1 Enter element to be added at rear end :22 Elements in a deque are :11 22 Menu 1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit. Enter choice :1 Enter element to be added at rear end :11 Elements in a deque are :11 Menu 1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit.DQ->item[x]).printf(“%d\t”.

1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit. Enter choice :3 Element 11 is deleted from front : Elements in a deque are :22 33 Menu 1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit. Enter choice :2 Deque is full at front end Menu 1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit. Enter choice :5 . Enter choice :2 Element 11 is deleted from front : Elements in a deque are :22 33 Menu 1: insert at rear end 2: insert at front end 3: delete from front end 4: delete from rear end 5: exit.

Ex.No: Date: IMPLEMENTATION OF EXPRESSION TREE AIM: To write a ‘C’ program to implement expression tree. ALGORITHM: STEP 1: Create a tree and check whether it is empty or not STEP 2: Then get the expression STEP 3: Convert the given expression in prefix and postfix form .RESULT: Thus the program for deque operation was executed and the output was verified.

. struct node *left.STEP 4: Display the result STEP 5: Exit the program PROGRAM CODING: #include<stdio.h> #include<ctype. }btree.h> #include<conio.h> #include<alloc. struct node *right.h> #define size 20 typedef struct node { char data.

char exp[80]. printf("\nThe inorder traversal is :\n"). top=-1. void main() { btree *root. int top. postorder(root). scanf("%s".exp). clrscr(). root=create(exp). inorder(root). btree *create(char exp[80]). printf("\nThe postorder traversal is :\n"). } . preorder(root). printf("\nThe preorder traversal is :\n").btree *stack[size]. getch(). printf("\nThe tree is created"). void postorder(btree *root). void preorder(btree *root). void inorder(btree *root). printf("\nEnter the postfix expression:").

. temp->left=temp->right=NULL. temp->left=pop(). int pos.tree *create(char exp[]) { btree *temp. pos=0. else if(ch=='+'||ch=='-'||ch=='*'||ch=='/') { temp->right=pop(). btree *pop(). ch=exp[pos]. temp->data=ch. push(temp). while(ch!='\0') { temp=(btree*)malloc(sizeof(btree)). if(isalpha(ch)) push(temp). char ch. } else printf("Invalid character\n"). void push(btree *).

ch=exp[pos]. return(temp). } void inorder(btree *root) { . stack[top]=node. top++. if(top==-1) printf("\nStack is empty"). node=stack[top]. return(node). } void push(btree *node) { if(top+1>=size) printf("\nstack is Full"). } temp=pop(). } btree *pop() { btree *node.pos++. top--.

if(temp!=NULL) { inorder(temp->left).temp->data). inorder(temp->right).temp->data). temp=root. if(temp!=NULL) { . temp=root. preorder(temp->right). } } void preorder(btree *root) { btree *temp. temp=root. if(temp!=NULL) { printf("%c". } } void postorder(btree *root) { btree *temp. preorder(temp->left).btree *temp. printf("%c".

printf("%c". } } OUTPUT: Enter the postfix expression:ab*cd/+ The tree is created The inorder traversal is: a*b+c/d The preorder traversal is: +*ab/cd The postorder traversal is: ab*cd/+ .temp->data).postorder(temp->left). postorder(temp->right).

RESULT: Thus the implementation of Expression tree is done and the program is executed.No: Date: IMPLEMENTATION OF BINARY SEARCH TREE AIM: To write a c program to implement binary search tree ALGORITHM: Step 1: Start Step 2: Create a structure named treenode . Ex.

h> #include<conio.h> #include<stdlib.Step 3: Write a function to find the min element and the maximum element Step 4: Write a function to insert. delete and to display the elements in inorder traversal Step 5: Exit the program PROGRAM CODING: #include<stdio. struct treenode *left. .h> #define NULL 0 struct treenode { int element. struct treenode *right. }.

} position findmin(searchtree t) { . if(t==NULL) exit(0).*searchtree. t->left=t->right=NULL.t->right). return t. } } else if(x<t->element) t->left=insert(x. searchtree insert(int x.typedef struct treenode *position. else if(x>t->element) t->right=insert(x.t->left). else { t->element=x.searchtree t) { if(t==NULL) { t=(struct treenode*)malloc(sizeof(struct treenode)).

} searchtree rem(int x.searchtree t) { position temp. else return findmin(t->left). } position findmax(searchtree t) { if(t==NULL) return NULL. . else if(t->left==NULL) return t.if(t==NULL) return NULL. else return findmax(t->right). else if(t->right==NULL) return t.

if(t->left==NULL) t=t->right.t->left). else if(t->left&&t->right) { temp=findmin(t->right). else if(x>t->element) t->right=rem(x. else if(x<t->element) t->left=rem(x. free(temp).t->right). t->element=temp->element. } else { temp=t.t->right). .if(t==NULL) printf("\nElement not found"). t->right=rem(t->element. else if(t->right==NULL) t=t->left.

} void intrav(searchtree head) { if(head==NULL) return. position node. } void main() { int n.&n). printf("Enter the elements:\n"). if(head->right!=NULL) intrav(head->right). if(head->left!=NULL) intrav(head->left).dat. searchtree t=NULL.i.head->element).ch. printf("%d\t". scanf("%d". . printf("Enter no of elements:\n").} return t. clrscr().

&ch). } intrav(t). break. do { printf("\n\n"). 3 -> Find Minimum\n").t). printf("\nEnter your choice:").&dat). printf("\n printf("\n printf("\n printf("\n printf("\n 2 -> Delete a node\n"). 5 -> Display(Inorder Traversal\n").for(i=1. scanf("%d". . 6 -> Exit\n").&dat). printf("\n ****MENU****\n"). 4 -> Find Maximum\n"). t=insert(dat. t=insert(dat.i++) { scanf("%d". switch(ch) { case 1:printf("\nEnter the element to be inserted:").i<=n. printf("\nEnter 1 -> Insert a node\n"). scanf("%d".t).

break.case 2:printf("\n Enter the node to be deleted:"). printf("\nThe maximum element is %d".t). case 5:intrav(t). break. break.node->element). break. } OUTPUT: Enter no of elements: 5 Enter the elements: . } }while(ch!=6). printf("\nThe minimum element is %d". scanf("%d". getch(). case 4:node=findmax(t).node->element). t=rem(dat. case 3:node=findmin(t).&dat). case 6:exit(0).

45 2 15 33 7 2 7 15 33 45 ****MENU**** Enter 1 -> Insert a node 2 -> Delete a node 3 -> Find Minimum 4 -> Find Maximum 5 -> Display(Inorder Traversal 6 -> Exit Enter your choice:5 .

2 7 15 33 45 ****MENU**** Enter 1 -> Insert a node 2 -> Delete a node 3 -> Find Minimum 4 -> Find Maximum 5 -> Display(Inorder Traversal 6 -> Exit Enter your choice:1 Enter the element to be inserted : 18 ****MENU**** Enter 1 -> Insert a node .

2 -> Delete a node 3 -> Find Minimum 4 -> Find Maximum 5 -> Display(Inorder Traversal 6 -> Exit Enter your choice:3 The minimum element is 2 ****MENU**** Enter 1 -> Insert a node 2 -> Delete a node 3 -> Find Minimum 4 -> Find Maximum .

5 -> Display(Inorder Traversal 6 -> Exit Enter your choice:2 Enter the node to be deleted:33 ****MENU**** Enter 1 -> Insert a node 2 -> Delete a node 3 -> Find Minimum 4 -> Find Maximum 5 -> Display(Inorder Traversal 6 -> Exit .

No: Date: IMPLEMENTATION OF AVL TREE Aim: To Implement Insertion in AVL Trees Algorithm: 1.Enter your choice:5 2 7 15 18 45 RESULT: Thus the implementation of Binary search tree is done and the program is executed. Ex. Create a class AVl tree and declare all its member variables and functions .

-1 then we have to rotate the tree one time left or right or Double rotate 5. If the option is 4. 0. display the tree contents in preorder and postorder formats 6.h> #include<conio. create a binary tree. avltree left.h> #include<alloc. . If the option is 2.h> typedef struct node *pos. Get the user option if tge choice is 1. avltree t. get the element to be searched and display whether the element is present or Not. }.2. typedef struct node *avltree. If the balance factor is not equal to 1. If the option is 3. with the values and considering the Balance factor 3. The balance factor=no of left child-no of right child 4. struct node { int element. avltree insert(int. exit the program Program coding: #include<stdio. int height. 7. avltree right.h> #include<stdlib.avltree).

int). t=insert(ele. printf("\nEnter your choice:"). Display\n"). break. Insertion\n"). scanf("%d". scanf("%d". void main() { int ch.&ele). getch().t).avltree t) { if(t==NULL) . pos doublerotatewithleft(pos). pos singlerotatewithleft(pos). case 2: printf("\nThe elements in the AVL TREE are:"). switch(ch) { case 1: printf("\nEnter the element to be inserted:"). void display(avltree). clrscr(). Exit\n"). pos singlerotatewithright(pos). break. pos doublerotatewithright(pos).ele. printf("\nThe element is inserted"). } avltree insert(int x. t=NULL. break. do { printf("\nMENU\n"). int height(pos p).int max(int. printf("\n3. printf("\n2.&ch). printf("\n1. display(t). } }while(ch<4). case 3: exit(0).

return t.int q) { . else { t->element=x. else t=doublerotatewithright(t).t->right).{ t=(node *)malloc(sizeof(struct node)).t->left). else return p->height. if(height(t->right)-height(t->left)==2) if(x>t->left->element) t=singlerotatewithright(t). else t=doublerotatewithleft(t). t->left=t->right=NULL. } t->height=max(height(t->left). } int max(int p. } int height(pos p) { if(p==NULL) return -1. if(t==NULL) exit(0). } } else if(x<t->element) { t->left=insert(x.height(t->right))+1.t->height=0. if(height(t->left)-height(t->right)==2) if(x<t->left->element) t=singlerotatewithleft(t). } else if(x>t->element) { t->right=insert(x.

k1->height=max(height(k1->left). k1=k2->left. return k2. } void display(avltree t) { if(t!=NULL) { display(t->left). k2->left=k1->right. k1->right=k2->left. k2->height=max(height(k2->left).t->element). k2->left=k1.height(k2->right))+1. return k1.k2->height)+1. else return q. } pos singlerotatewithleft(pos k2) { pos k1. k2=k1->right. return singlerotatewithleft(k3). } pos doublerotatewithleft(pos k3) { k3->left=singlerotatewithright(k3->left). display(t->right). printf("\n%d". } pos doublerotatewithright(pos k1) { k1->right=singlerotatewithleft(k1->right). } . k1->height=max(height(k1->left). } pos singlerotatewithright(pos k1) { pos k2. k2->height=max(k1->height. k1->right=k2.if(p>q) return p.height(k2->right))+1.height(k1->right))+1. return singlerotatewithright(k1).

Display 3. Display 3. Display 3. Insertion 2. Insertion 2.} OUTPUT: MENU 1. Display 3. Exit Enter your choice:1 Enter the element to be inserted:33 The element is inserted MENU 1. Insertion 2. Exit Enter your choice:1 Enter the element to be inserted:17 . Exit Enter your choice:1 Enter the element to be inserted:12 The element is inserted MENU 1. Insertion 2. Exit Enter your choice:1 Enter the element to be inserted:6 The element is inserted MENU 1.

Insertion 2. Exit Enter your choice:2 The elements in the AVL TREE are: 6 12 17 33 RESULT: Thus the C program To Implement Insertion in AVL Trees was written and verified. Display 3. .The element is inserted MENU 1.

Sign up to vote on this title
UsefulNot useful