I have problem with printing the binary tree.After i put the numbers it is just closing.Can't find the problem,somehow it ignores the function called "printukas".
#include <stdio.h>
#include <stdlib.h>
struct tree
{
int data;
struct tree *rajt;
struct tree *left;
};
typedef struct tree node;
int main()
{
init();
}
int insert(node *nju,node *root)
{
if(nju->data > root->data)
{
if(root->rajt=NULL)
root->rajt=nju;
else
insert(nju,root->rajt);
}
if(nju->data < root->data)
{
if(root->left=NULL)
root->left=nju;
else
insert(nju,root->left);
}
printukas();
}
int printukas(struct tree *node)
{
if( node != NULL)
{
printukas(node->left);
printukas(node->rajt);
printf("%d\n",node->data);
}
system("PAUSE");
return 0;
}
int init()
{
int num,n,i;
node *root=NULL;
node *nju=NULL;
printf("How many elements do you want?");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter elements for a tree:\n");
scanf("%d",&num);
}
nju=malloc(sizeof(node));
nju->data=num;
nju->left = NULL;
nju->rajt = NULL;
if(root == NULL)
root=nju;
else
{
insert(nju,root);
}
}