#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

How can we use the preprocessor #if and #elseif.

2 Answers  


What is differance between Abstract and Interface

3 Answers  


What are the components of marker interface?

0 Answers  


What is oops in simple words?

0 Answers  


difference between class and object

10 Answers   Chandan, IBM, Magic Soft,






What is object and example?

0 Answers  


Have you ever interfaced with a database?

2 Answers   IBM,


what is new modifier in C#

8 Answers   HCL,


Program to read a comment string

1 Answers   IBM,


what is data abstraction with example.

1 Answers  


polymorphism means?

6 Answers   BFL,


which is best institute to learn c,c++ in ameerpet hyderabad

1 Answers  


Categories