#include #include struct NODE_STRUCT { char value; struct NODE_STRUCT* lch; /* link to left child */ struct NODE_STRUCT* rch; /* link to right child */ }; typedef struct NODE_STRUCT NODE; typedef struct NODE_STRUCT* PNODE; #define merror() {printf("memory allocation error\n");exit(1);} /* function Insert -------------------------------------------- */ NODE Insert(PNODE n,char c) { if (n == NULL) { /* at the end of path, or tree not built yet */ if ((n = malloc(sizeof(NODE))) == NULL) merror(); n->value = c; n->lch = n->rch = NULL; return n; } if (c < n->value) /* go left */ n->lch = Insert(n->lch,c); else /* go right */ n->rch = Insert(n->rch,c); return n; }/*end Insert*/ /* function Show ---------------------------------------------- */ void Show(PNODE n) { if (n == NULL) return; Show(n->lch); printf(" %c",n->value); Show(n->rch); }/*end Show*/