#include<stdio.h>
#include<conio.h>
#include<alloc.h>
int count=0;
struct tree
{
int info;
struct tree* left;
struct tree* right;
}*root,*q,*n,*t;
void preorder(struct tree* tree1)
{
int num;
if(tree1==NULL)
{
// tree1=(struct tree*)malloc(sizeof(struct tree));
printf("enter the element");
scanf("%d",&num);
tree1->info=num;
tree1->left=NULL;
tree1->right=NULL;
preorder(tree1->left);
preorder(tree1->right);
// count++;
}
else
{
if((count%2)==0)
{
printf("enter the element");
scanf("%d",&num);
q=root;
while(q->left!=NULL)
{
q=q->left;
}
t=(struct tree*)malloc(sizeof(struct tree));
t->info=num;
t->left=NULL;
t->right=NULL;
q->left=t;
tree1->left=t->left;
tree1->left=t->right;
preorder(tree1->left);
preorder(tree1->right);
count++;
}
else if((count%2)==1)
{
printf("enter the element");
scanf("%d",&num);
q=root;
while(q->right!=NULL)
{
q=q->right;
}
t=(struct tree*)malloc(sizeof(struct tree));
t->info=num;
t->left=NULL;
t->right=NULL;
q->right=t;
tree1->left=t->left;
tree1->left=t->right;
preorder(tree1->left);
preorder(tree1->right);
count++;
}
}
}
void display(struct tree* tree1)
{
if(tree1!=NULL)
{
printf("%d \n",tree1->info);
display(tree1->left);
display(tree1->right);
}
}
void main()
{
void display(struct tree* root);
root=(struct tree*)malloc(sizeof(struct tree));
void preorder(struct tree* root);
int i=1,j;
while(i==1)
{
printf("enter 1 for insertion & 2 for display");
scanf("%d",&j);
if(j==1)
{
preorder(root);
}
else if(j==2)
{
display(root);
}
printf("enter 1 for continue and 2 for exit");
scanf("%d",&i);
}
}
for more codes you can visit http://codesofprogramming.blogspot.in/
#include<conio.h>
#include<alloc.h>
int count=0;
struct tree
{
int info;
struct tree* left;
struct tree* right;
}*root,*q,*n,*t;
void preorder(struct tree* tree1)
{
int num;
if(tree1==NULL)
{
// tree1=(struct tree*)malloc(sizeof(struct tree));
printf("enter the element");
scanf("%d",&num);
tree1->info=num;
tree1->left=NULL;
tree1->right=NULL;
preorder(tree1->left);
preorder(tree1->right);
// count++;
}
else
{
if((count%2)==0)
{
printf("enter the element");
scanf("%d",&num);
q=root;
while(q->left!=NULL)
{
q=q->left;
}
t=(struct tree*)malloc(sizeof(struct tree));
t->info=num;
t->left=NULL;
t->right=NULL;
q->left=t;
tree1->left=t->left;
tree1->left=t->right;
preorder(tree1->left);
preorder(tree1->right);
count++;
}
else if((count%2)==1)
{
printf("enter the element");
scanf("%d",&num);
q=root;
while(q->right!=NULL)
{
q=q->right;
}
t=(struct tree*)malloc(sizeof(struct tree));
t->info=num;
t->left=NULL;
t->right=NULL;
q->right=t;
tree1->left=t->left;
tree1->left=t->right;
preorder(tree1->left);
preorder(tree1->right);
count++;
}
}
}
void display(struct tree* tree1)
{
if(tree1!=NULL)
{
printf("%d \n",tree1->info);
display(tree1->left);
display(tree1->right);
}
}
void main()
{
void display(struct tree* root);
root=(struct tree*)malloc(sizeof(struct tree));
void preorder(struct tree* root);
int i=1,j;
while(i==1)
{
printf("enter 1 for insertion & 2 for display");
scanf("%d",&j);
if(j==1)
{
preorder(root);
}
else if(j==2)
{
display(root);
}
printf("enter 1 for continue and 2 for exit");
scanf("%d",&i);
}
}
for more codes you can visit http://codesofprogramming.blogspot.in/
No comments:
Post a Comment