int disptree(struct kpnode* node) { printf("node data: %c\n", node->data); if (node->lnext) { printf("child 1 "); disptree(node->lnext); } if (node->rnext) { printf("child 2 "); disptree(node->rnext); } return 0; }
int main() { int i; ptree=malloc(sizeof(tleaf)); *ptree=leafempty; for(i=0; i< sizeof(vdata)/sizeof(char*);i++) addToTree(ptree,vdata[i],mycmp); disptree(ptree,printstr); return 0; }
int main(int argc, char **argv) { int fd1, fd2; struct lnode *clist; struct kpnode *tree; if (argc < 1) { fprintf(stderr, "Error: not enough arguments.\n"); return 1; } if ((fd1 = open(argv[1], O_RDONLY)) < 0) { fprintf(stderr, "Error: cannot open file.\n"); return 1; } if ((clist = mklist(fd1)) == 0) { fprintf(stderr, "Error while compiling frequencies.\n"); return 1; } displist(clist); tree = mktree(clist); disptree(tree); encode(); /*save(fd2);*/ remlnode(&clist); /*remnode(&tree);*/ close(fd1); return 0; }
void disptree(tleaf*ptree,void (*printdata)(void*)) { if (ptree->pl) disptree(ptree->pl,printdata); printdata(ptree->pdata); if (ptree->pr) disptree(ptree->pr,printdata); }