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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

sdut 3346 sdut 3344 Runtime Error Runtime Error?

發(fā)布時間:2025/4/16 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 sdut 3346 sdut 3344 Runtime Error Runtime Error? 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

數(shù)據(jù)結(jié)構(gòu)實(shí)驗(yàn)之二叉樹七:葉子問題

Time Limit:?1000MS?Memory Limit:?65536KB Submit?Statistic?Discuss

Problem Description

已知一個按先序輸入的字符序列,如abd,,eg,,,cf,,,(其中,表示空結(jié)點(diǎn))。請建立該二叉樹并按從上到下從左到右的順序輸出該二叉樹的所有葉子結(jié)點(diǎn)。

Input

輸入數(shù)據(jù)有多行,每一行是一個長度小于50個字符的字符串。

Output

按從上到下從左到右的順序輸出二叉樹的葉子結(jié)點(diǎn)。

Example Input

abd,,eg,,,cf,,, xnl,,i,,u,,

Example Output

dfg uli

#include <iostream> #include <string.h> #include <queue> #include <stack> #include <malloc.h> using namespace std; typedef struct btree {char data;btree *lchild,*rchild; }btree; int i; char ch[100]; btree *root; btree * createbtree(btree *&root) {char c;c=ch[i++];if(c==',')root=NULL;else{root=(btree *)malloc(sizeof(btree));root->data=c;root->lchild=createbtree(root->lchild);root->rchild=createbtree(root->rchild);}return root; } void levelorder() {btree *b=root;queue<btree*>Queue;Queue.push(b);while(!Queue.empty()){b=Queue.front();Queue.pop();//這個沒有返回值if(b->lchild==NULL&&b->rchild==NULL)cout<<b->data;if(b->lchild!=NULL)Queue.push(b->lchild);if(b->rchild!=NULL)Queue.push(b->rchild);}cout<<endl; } int main() {while(cin>>ch){i=0;root=createbtree(root);levelorder();}return 0; }

數(shù)據(jù)結(jié)構(gòu)實(shí)驗(yàn)之二叉樹五:層序遍歷

Time Limit:?1000MS?Memory Limit:?65536KB Submit?Statistic?Discuss

Problem Description

已知一個按先序輸入的字符序列,如abd,,eg,,,cf,,,(其中,表示空結(jié)點(diǎn))。請建立二叉樹并求二叉樹的層次遍歷序列。

Input

輸入數(shù)據(jù)有多行,第一行是一個整數(shù)t?(t<1000),代表有t行測試數(shù)據(jù)。每行是一個長度小于50個字符的字符串。

Output

輸出二叉樹的層次遍歷序列。

Example Input

2 abd,,eg,,,cf,,, xnl,,i,,u,,

Example Output

abcdefg xnuli

#include <iostream> #include <queue> #include <malloc.h> using namespace std; typedef struct btree {char data;btree *lchild,*rchild; }btree; char ch[55]; int i; void createbtree(btree *&root) {char c=ch[i++];if(c==',')root=NULL;else//按先序建立二叉樹,要是按照中序后序的順序自己應(yīng)該會會寫出{root=(btree *)malloc(sizeof(btree));root->data=c;createbtree(root->lchild);createbtree(root->rchild);} } void levelorder(btree *&root) {queue<btree*>Queue;btree *p=root;Queue.push(root);while(!Queue.empty()){p=Queue.front();cout<<p->data;Queue.pop();if(p->lchild!=NULL)Queue.push(p->lchild);if(p->rchild!=NULL)Queue.push(p->rchild);} } int main() {int n;while(cin>>n){while(n--){i=0;cin>>ch;btree *root;root=(btree*)malloc(sizeof(btree));createbtree(root);levelorder(root);cout<<endl;}}return 0; }/*************************************************** User name: YT1658506207邵雪源 Result: Runtime Error Take time: 0ms Take Memory: 0KB Submit time: 2017-11-06 18:31:30 ****************************************************/

總結(jié)

以上是生活随笔為你收集整理的sdut 3346 sdut 3344 Runtime Error Runtime Error?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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