0% found this document useful (0 votes)
6 views4 pages

INSERTIONSORT26

Insertion sort program

Uploaded by

baliramjagtap675
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

INSERTIONSORT26

Insertion sort program

Uploaded by

baliramjagtap675
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PRACTICAL:26

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

typedef struct node

int data;

struct bstnode*left,*right;

}bstnode*inti()

return NULL;

bstnode *insert(bstnode *T,int x)

if(T==NULL)

bstnode*r=(bstnode*)malloc(sizeof(bstnode));

r->data=x;

r->left=NULL;

r->right=NULL;

return r;

if(x>T->data)

T->right=insert(T->right,x);

else

if(x<T->data)

T->left=insert(T->left,x);
}

return T;

bstnode*create()

int n,x,i;

bstnode*root=NULL;

printf("\n enter the number of node:");

scanf("%d",&n);

printf("\n enter tree value:\n");

for(i=0;i<n;i++)

scanf("%d",&x);

root=insert(root,x);

return root;

void inorder(bstnode*T)

if(T!=NULL)

inorder(T->left);

printf("%d\t",T->data);

inorder(T->right);

void preorder(bstnode*T)

if(T!=NULL)

printf("%d\t",T->data);
preorder(T->left);

preorder(T->right);

void postorder(bstnode*T)

if(T!=NULL)

postorder(T->left);

postorder(T->right);

printf("%d\t",T->data);

void main()

bstnode*root=NULL;

int x;

clrscr();

root=create();

printf("\n binary search tree created successfully\n");

printf("\n enter a value to insert:");

scanf("%d",&x);

root=insert(root,x);

printf("\n value inserted successfully\n");

printf("\n ///INORDER/// \n");

inorder(root);

printf("\n ///PREORDER/// \n");

preorder(root);

printf("\ ///POSTORDER/// \n");

postorder(root);

getch();
}

You might also like