#include<stdio.h>
#include<conio.h>
#include<stdio.h>
void maketree(struct node**);
void inorder(struct node**);
struct node{
struct node *left;
struct node *right;
int data;
}
void main()
{
struct node *root;
root=NULL;
printf("Enter root");
maketree(&root);
preorder(&root);
getch();
}
void maketree(struct node **root)
{
int num;
struct node *temp;
if(*root==NULL){
//printf("Enter number");
scanf("%d",&num);
temp=(struct node*)malloc(sizeof(struct node));
temp->data=num;
temp->left=temp->right=NULL;
}
if((*root)->data!=0){
printf("enter left of %d ",(*root)->data);
maketree(&(*root)->left);
printf("Enter right of %d ",(*root)->data);
maketree(&(*root)->right);
}
}
void ineorder(struct node *root)
{
if(root!=NULL)
inorder(root->left);
printf("%d->",root->data);
inorder(root->right);
}
fsl4faisal -4 Newbie Poster
gusano79 247 Posting Shark
fsl4faisal -4 Newbie Poster
fsl4faisal -4 Newbie Poster
gusano79 247 Posting Shark
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.