#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

wht is major diff b/w c and c++?

10 Answers  


what is static?

4 Answers  


hi all..i want to know oops concepts clearly can any1 explain??

0 Answers   Eureka Forbes,


suppose A is a base class and B is the derved class. Both have a method foo which is defined as a virtual method in the base class. You have a pointer of classs B and you typecast it to A. Now when you call pointer->foo, which method gets called? The next part of the question is, how does the compiler know which method to call?

3 Answers   EA Electronic Arts,


what is use to destroy an object? illustrate.

5 Answers   TCS,






What is the fundamental idea of oop?

0 Answers  


Can we define a class within the interface?

0 Answers  


What is abstraction and encapsulation?

0 Answers  


why in java first invoke public static void main(String args[]) method????Why not public static void method1(String args[])??

1 Answers  


what is the difference between class to class type conversion and copy constructor ?

2 Answers  


what is the advantage in software? what is the difference between the software developer and Engineer

1 Answers  


When not to use object oriented programming?

0 Answers  


Categories