HMtrees.patricia.coman

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node
{
    int val;
    struct node *left, *right;
}NodeT;


NodeT* createBinTree()
{
    NodeT *p=(NodeT*)malloc(sizeof(NodeT));
    char *c=(char *)malloc(sizeof(char));
    scanf("%s", c);

    if (strcmp(c,"0")==0)
        return NULL;
    else
        {p->val=c;
         p->right=createBinTree();
         p->left=createBinTree();
        }
    return p;
}



void preorder(NodeT *root, int *level)
{
    if (root != NULL)
    {
        printf("%d", root->val); *level++;
        preorder(root->left,level);
        preorder(root->right,level);
    }
}

void inorder(NodeT *root)
{
    if (root != NULL)
    {
        inorder(root->left);
        printf("%s", root->val);
        inorder(root->right);
    }
}

void postorder(NodeT *root)
{
    if (root != NULL)
    {
        postorder(root->left);
        postorder(root->right);
        printf("%d", root->val);
    }
}

void removeSpaces(char* source)
{
  char* i = source;
  char* j = source;
  while(*j != 0)
  {
    *i = *j++;
    if(*i != ' ')
      i++;
  }
  *i = '\0';
}



int main()
{
    FILE *fp;
    fp=fopen("test.txt", "rw");

    char a[256];
    fgets(a, 256, fp);

    int len=strlen(a);
    strrev(a);
    removeSpaces(a);
    printf("%s",a);



   NodeT *root=createBinTree();

   printf("\n");
    inorder(root);

    return 0;
}