#include <stdio.h>
#include <alloc.h>
#include <stdlib.h>
#include <conio.h>
void insert(struct btreenode **, int);
void inorder(struct btreenode *);
struct btreenode
{
struct btreenode *leftchild;
struct btreenode *rightchild;
int data;
};
main()
{
struct btreenode *bt;
bt=(struct btreenode *)NULL;
int req,i=1,num;
clrscr();
printf("Enter number of nodes");
scanf("%d",&req);
while(i<=req)
{
printf("Enter element");
scanf("%d",&num);
insert(&bt,num);
i++;
}
inorder(bt);
}
void insert(struct btreenode **sr, int num)
{
if(*sr==NULL)
{
*sr=(struct btreenode *)malloc (sizeof(struct btreenode));
(*sr)->leftchild=(struct btreenode *)NULL;
(*sr)->rightchild=(struct btreenode *)NULL;
(*sr)->data=num;
return;
}
else
{
if(num < (*sr)->data)
insert(&(*sr)->leftchild,num);
else
insert(&(*sr)->rightchild,num);
}
return;
}
void inorder(struct btreenode *sr)
{
if(sr!=(struct btreenode *)NULL)
{
inorder(sr->leftchild);
printf("\n %d",sr->data);
inorder(sr->rightchild);
}
else
return;
}



please Modify the given program and add two methods for post
order and pre order traversals.


No Answer is Posted For this Question
Be the First to Post Answer

Post New Answer

More OOPS Interview Questions

polymorphism means?

6 Answers   BFL,


How do you achieve runtime polymorphism?

0 Answers  


1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

2 Answers  


i ahve v low % in 12th n BSC which is aroun 50 coz science was imposed on me......nw m doin MCA n my aggregate in above 74%,what shud i say if asked about low previous percentage??????

4 Answers  


What is polymorphism in oops with example?

0 Answers  






how to tackle technical questions

1 Answers  


can you give the dynamic polymorphism types?

2 Answers   Wipro,


Why is object oriented programming so hard?

0 Answers  


What are different oops concepts?

0 Answers  


What is polymorphism give a real life example?

0 Answers  


What is virtual function?where and when is it used?

2 Answers   Sitel,


When you define a integer it gets stored in which data structure?(Stack or a heap)

2 Answers   emc2,


Categories