Please help..
The output must be "-B -C -A ", but when I run it, It shows "- -B -C - A ".
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct Node
{
char data;
struct Node *right;
struct Node *left;
};
typedef struct Tree
{
Node *root;
};
Tree tree;
void iLeft(Node* node, char data)
{
Node* current = (Node*) malloc(sizeof(Node*));
current->left = NULL;
current->right = NULL;
current->data = data;
node->left = current;
}
void iRight(Node* node, char data)
{
Node* current = (Node*) malloc(sizeof(Node*));
current->left = NULL;
current->right = NULL;
current->data = data;
node->right = current;
}
void print(Node* node)
{
if(node->left != NULL)
print(node->left);
if(node->right != NULL)
print(node->right);
printf("-%c ", node->data);
}
int main()
{
char ins[] = {"ABC"};
tree.root->data = ins[0];
iLeft(tree.root, ins[1]);
iRight(tree.root, ins[2]);
print(tree.root);
getch();
return 0;
}