发布时间:2019-07-29 17:00:54
这个程序哪里错了?为什么最后一个结点出不了。。。
#include <stdio.h>
#include <stdlib.h>
/*二叉树链接存储的头文件*/
typedef char datatype; /*结点属性值的类型*/
typedef struct node{ /*二叉树结点的类型*/
datatype data;
struct node *lchild,*rchild;
}bintnode,*bintree;
bintree createbintree()
{/*按照前序遍历的顺序建立一棵给定的二叉树*/
char ch;
bintree t;
if ((ch=getchar())=='#')
t=NULL;
else
{
t=(bintnode *)malloc(sizeof(bintnode));
t->data=ch;
t->lchild=createbintree();
t->rchild=createbintree();
}
return t;
}
void inorder(bintree t)
{ /*中序遍历二叉树的递归算法*/
if (t)
{
inorder(t->lchild);
printf("%c",t->data);
inorder(t->rchild);
}
}
bintree inlast(bintree t) /*将本函数补充完整,并进行测试*/
{
datatype p;
if(t)
{
inlast(t->lchild);
p=t->data;
inlast(t->rchild);
}
return p;
}
void main() /*将主函数补充完整*/
{
bintree root;
printf("请输入二叉树各结点的值:");
root=createbintree();
printf("\n中序遍历结果是: "); inorder(root);
printf("\n二叉树中序遍历下最后一个结点是: ");
printf("%c",inlast(root));
printf("\n");
}
你的
bintree inlast(bintree t) 返回的是bintree ,也就是一个指针
你怎么能用
printf("%c",inlast(root));
输出它的值 ?