日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

信管家源代码c语言,用队列实现按层次创建二叉树的源代码,最好是C语言

發(fā)布時間:2023/12/2 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 信管家源代码c语言,用队列实现按层次创建二叉树的源代码,最好是C语言 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

滿意答案

Dcool

2016.08.27

采納率:58%????等級:9

已幫助:416人

隊列??你每輸入一個節(jié)點將其存入隊列中,再輸入它的左孩子,它的左孩子也會入隊,我們取的時候應先取該節(jié)點的左孩子,

LZ一定要用隊列也行,但絕對不是正確的選擇!

隊列如下:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990#include using namespace std;typedef struct bitnode{????char data;????struct bitnode *lchild,*rchild;}*bitree,tree;int number=0;void createbitree(bitree &t){????char c;????int i=0,r=0,f=0;//r,f分別指向隊首和隊尾????bitree p=NULL,temp=NULL,pre=NULL,s[100];????s[0]=NULL;????int lflag[100]={0};????int rflag[100]={0};????printf("請輸入根節(jié)點:");????t=new tree;????t->lchild=t->rchild=NULL;????scanf("%c",&t->data);????temp=pre=t->lchild;????s[++i]=t;????f=i;????p = t;????while(f!=r)????{????????if(p->lchild==NULL&&lflag[i]==0)????????{????????????printf("請輸入%c的左孩子:",p->data);????????????fflush(stdin);????????????scanf("%c",&c);????????????if(c!='#')????????????{????????????????p->lchild = new tree;????????????????p = p->lchild;????????????????p->lchild=p->rchild=NULL;????????????????p->data = c;????????????????s[++f]=p;????????????????i = f;????????????????lflag[i]=rflag[i]=0;????????????}????????????else????????????????lflag[i]=1;????????}????????else if(p->rchild==NULL&&rflag[i]==0)????????{????????????printf("請輸入%c的右孩子:",p->data);????????????fflush(stdin);????????????scanf("%c",&c);????????????if(c!='#')????????????{????????????????p->rchild = new tree;????????????????p = p->rchild;????????????????p->lchild=p->rchild=NULL;????????????????p->data = c;????????????????s[++f]=p;????????????????i=f;????????????????lflag[i]=rflag[i]=0;????????????}????????????else????????????{????????????????rflag[i]=1;????????????????p=s[++r];????????????????i=r;????????????}????????}????????else????????{????????????p=s[++r];????????????i=r;????????}????}}void preorder(bitree &t)//遍歷二叉樹,輸出函數(shù){????if (t!=0)????{????????cout<data<lchild);????????preorder(t->rchild);????}}void main(){????bitree t;????t=0;????createbitree(t);????cout<

在此,強烈建議LZ用棧,更符合樹的輸入層次:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283#include using namespace std;typedef struct bitnode{????char data;????struct bitnode *lchild,*rchild;}*bitree,tree;int number=0;void createbitree(bitree &t){????char c;????int i=0;????bitree p=NULL,temp=NULL,pre=NULL,s[100];????s[0]=NULL;????int lflag[100]={0};????int rflag[100]={0};????printf("請輸入根節(jié)點:");????t=new tree;????t->lchild=t->rchild=NULL;????scanf("%c",&t->data);????temp=pre=t->lchild;????s[++i]=t;????p = t;????while(s[i]!=NULL)????{????????if(p->lchild==NULL&&lflag[i]==0)????????{????????????printf("請輸入%c的左孩子:",p->data);????????????fflush(stdin);????????????scanf("%c",&c);????????????if(c!='#')????????????{????????????????p->lchild = new tree;????????????????p = p->lchild;????????????????p->lchild=p->rchild=NULL;????????????????p->data = c;????????????????s[++i]=p;????????????????lflag[i]=rflag[i]=0;????????????}????????????else????????????????lflag[i]=1;????????}????????else if(p->rchild==NULL&&rflag[i]==0)????????{????????????printf("請輸入%c的右孩子:",p->data);????????????fflush(stdin);????????????scanf("%c",&c);????????????if(c!='#')????????????{????????????????p->rchild = new tree;????????????????p = p->rchild;????????????????p->lchild=p->rchild=NULL;????????????????p->data = c;????????????????s[++i]=p;????????????????lflag[i]=rflag[i]=0;????????????}????????????else????????????{????????????????rflag[i]=1;????????????????p=s[--i];????????????}????????}????????else????????????p=s[--i];????}}void preorder(bitree &t)//遍歷二叉樹,輸出函數(shù){????if (t!=0)????{????????cout<data<lchild);????????preorder(t->rchild);????}}void main(){????bitree t;????t=0;????createbitree(t);????cout<

不懂追問!你的疑問往往是我要學習的地方!追問: 附件失效了

追答:逗……服了百度……老是出事

不行啊,傳不上去,

你QQ多少……我發(fā)郵件

01分享舉報

總結

以上是生活随笔為你收集整理的信管家源代码c语言,用队列实现按层次创建二叉树的源代码,最好是C语言的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。