//主要是验证下采用递推的算法对二叉树进行遍历:#include<stdio.h>#include<stdlib.h>#include<malloc.h>//二叉树的表示:#define error -1#define ok 1typedef struct BiTreeNode{//结点元素的数值:char data;struct BiTreeNode *lchild,*rchild;}Bnode,*Btree;//初始化一个二叉树,int creatree(Btree T);//对二叉树树结点的操作函数:int print(char e);//遍历二叉树结点:先序遍历法int preoder(Btree T,int(*vist)(char));//遍历二叉树结点:中序遍历法int inorder(Btree T,int(*vist)(char));//遍历二叉树结点:后序遍历法int postorder(Btree T,int(*vist)(char));//主函数:int main(int argc,char *argv[]){Btree R;int i,j;R=(Btree)malloc(sizeof(Bnode));i=creatree(R);printf("if i=1;表示初始化成功:%d\n",i);j=preoder(R,print);printf("if j=1;表示初始化成功:%\n",j);printf("\n");inorder(R,print);printf("\n");postorder(R,print);return 0;}//初始化一个二叉树:int creatree(Btree T){//按先后顺序输入二叉树结点值,空格表示空树:char ch;printf("输入字符\n");scanf("%c",&ch);if(ch==' ')T=NULL;else{if(!(T=(Bnode*)malloc(sizeof(Bnode))))return error;T->data=ch;creatree(T->lchild);creatree(T->rchild);}return ok;}//int print(char e){printf("%c\n",e);return ok;}//int preoder(Btree T,int(*vist)(char)){if(T){vist(T->data);preoder(T->lchild,vist);preoder(T->rchild,vist);return ok;}elsereturn error;}//int inorder(Btree T,int(*vist)(char)){if(T){inorder(T->lchild,vist);vist(T->data);inorder(T->rchild,vist);return ok;}elsereturn error;}int postorder(Btree T,int(*vist)(char)){if(T){postorder(T->lchild,vist);postorder(T->rchild,vist);vist(T->data);return ok;}elsereturn error;}怎么这个函数调试不出来,,在vc调试下,,卡在这里:vist(T->data);
2 回答
手掌心
TA贡献1942条经验 获得超3个赞
程序写多了,以下那些是多余的,定义函数,你下面并没有具体程序。
//初始化一个二叉树,
int creatree(Btree T);
//对二叉树树结点的操作函数:
int print(char e);
//遍历二叉树结点:先序遍历法
int preoder(Btree T,int(*vist)(char));
//遍历二叉树结点:中序遍历法
int inorder(Btree T,int(*vist)(char));
//遍历二叉树结点:后序遍历法
int postorder(Btree T,int(*vist)(char));
而且注释部分是用 /* */ 来实现的,要不然系统认为你的注释也是程序的部分。
四季花海
TA贡献1811条经验 获得超5个赞
//初始化一个二叉树,
int creatree(Btree T);
//对二叉树树结点的操作函数:
int print(char e);
//遍历二叉树结点:先序遍历法
int preoder(Btree T,int(*vist)(char));
//遍历二叉树结点:中序遍历法
int inorder(Btree T,int(*vist)(char));
//遍历二叉树结点:后序遍历法
int postorder(Btree T,int(*vist)(char));
添加回答
举报
0/150
提交
取消