亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

想要構造二叉樹函數及遍歷,以下操作該怎么修改嗎?

想要構造二叉樹函數及遍歷,以下操作該怎么修改嗎?

慕無忌1623718 2022-03-18 11:11:37
//主要是驗證下采用遞推的算法對二叉樹進行遍歷:#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));
而且注釋部分是用 /* */ 來實現的,要不然系統認為你的注釋也是程序的部分。

查看完整回答
反對 回復 2022-03-23
?
四季花海

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));



查看完整回答
反對 回復 2022-03-23
  • 2 回答
  • 0 關注
  • 188 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號