#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);
}

in this program i have to enter numbers in the tree
maketree() function is a recursive function
but it does not work properly.

in this program i have to enter numbers in the tree
maketree() function is a recursive function
but it does not work properly.

in this program i have to enter numbers in the tree
maketree() function is a recursive function
but it does not work properly.

Again, more detail would be helpful. What does "not work properly" mean to you here? What is it not doing that you expect it to? What is it doing right, if anything?

You'll get better results in this forum (and with software engineering in general) if you start asking yourself these questions--and answering them.

Just looking at the code, a few things stand out:

void maketree(struct node **root)

Why the double indirection? I don't think it's necessary, and it only confuses your code.

if(*root==NULL){
  //printf("Enter number");
  scanf("%d",&num);
  temp=(struct node*)malloc(sizeof(struct node));
  temp->data=num;
  temp->left=temp->right=NULL;
}

You create a new node here, but never assign anything to root , so it will always be NULL .

temp=(struct node*)malloc(sizeof(struct node));

You're allocating storage for all these nodes, but the memory is never freed. You should do that before the program exits. Here's an introduction to common malloc -related errors.

This article has been dead for over six months. Start a new discussion instead.