Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

data structure using binary search tree, Exercises of Database Programming

it has the step by step process to done the excercise on it

Typology: Exercises

2022/2023

Uploaded on 01/04/2023

Mathivanans
Mathivanans 🇮🇳

3 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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);
pf3
pf4
pf5

Partial preview of the text

Download data structure using binary search tree and more Exercises Database Programming in PDF only on Docsity!

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