



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
it has the step by step process to done the excercise on it
Typology: Exercises
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Program #include <stdio.h> #include <stdlib.h> struct Node{ struct Node left; int data; struct Node right; }head = NULL; struct Node Create_Node(int value){ struct Node newnode = (struct Node)malloc(sizeof(struct Node)); newnode -> left = NULL; newnode -> data = value; newnode -> right = NULL; return newnode; } void Insertion(struct Node **node,int value){ struct Node *temp = node; if(node == NULL){ *node = Create_Node(value);
printf("Inserted Successfully\n");} else if(temp->data>value) Insertion(&temp->left,value); else Insertion(&temp->right,value); } void preorder(struct Node *head){ if(head==NULL) return; else{ printf("%d ",head->data); preorder(head->left); preorder(head->right); } } void inorder(struct Node *head){ if(head==NULL) return; else{ inorder(head->left); printf("%d ",head->data); inorder(head->right); } }
int main() { int value,choice; do{ printf("1.Insert 2.Display 3.Exit\n"); printf("Enter the Choice: "); scanf("%d",&choice); switch(choice){ case 1: printf("Enter the value: "); scanf("%d",&value); Insertion(&head,value); break; case 2: Display(head); break; case 3: printf("Exiting..."); } }while(choice != 3); return 0; }
Output 1.Insert 2.Display 3.Exit Enter the Choice: 1 Enter the value: 10 Inserted Successfully 1.Insert 2.Display 3.Exit Enter the Choice: 1 Enter the value: 20 Inserted Successfully 1.Insert 2.Display 3.Exit Enter the Choice: 1 Enter the value: 30 Inserted Successfully 1.Insert 2.Display 3.Exit Enter the Choice: 2 Preorder : 10 20 30 Inorder : 10 20 30 Postorder : 30 20 10