二叉树的建议与遍历 出错了
二叉树的建议与遍历 出错了 (遍历出错了)直接上代码吧
#include "malloc.h"
#include "stdio.h"
typedef struct trees
{
char data;
struct trees *lchild,*rchild;
}treelist,*treelink;
void maketree(treelink &root);
void display(treelink root);
int main(int argc, char* argv[])
{
treelist *root;
root = (treelink)malloc( sizeof(treelist));
maketree(root);
display(root);
return 0;
}
void maketree(treelink &root)
{
char ch;
scanf("%c",&ch);
if (ch == '#')
{
root = NULL;
}
else
{
root = (treelink)malloc(sizeof(treelist));
root->data = ch;
maketree(root->lchild);
maketree(root->rchild);
}
}
void display(treelink root)
{
while (root != NULL)
{
printf("%c ",root->data);
display(root->lchild);
display(root->rchild);
}
}