#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

Which is the best institute in hyderabad for C/C++ and it also has fast track course structure.

13 Answers   Wipro,


Input: enter the value:1234 output: 1 2 3 4 write a program to get above output.....

4 Answers   Bally Technologies, IBM, SoftSol,


Write a program to implement OOPS concepts such as inheritance, polymorphism, friend function, operator overloading?

0 Answers   TCS,


What is the different between Applet and Application?

2 Answers  


Why is destructor used?

0 Answers  






You attempt to query the data base with this command: SELECT name, salary FROM employee WHERE salary=(SELECT salary FROM employee WHERE last name='Wagner' OR dept no=233) Choose most appropriate option from the following: 1)Sub-queries are not allowed in the where clause. 2)a multiple row sub-query used with a single row comparison operator. 3)a single row query is used with a multiple row comparison operator.

10 Answers   Zycus Infotech,


What is encapsulation example?

0 Answers  


Difference between new operator and operator new

2 Answers  


What does and I oop mean in text?

0 Answers  


How is polymorphism achieved?

0 Answers  


what is the usage of clas templates

5 Answers  


Where is pseudocode used?

0 Answers  


Categories