日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

sdut 3346 sdut 3344 Runtime Error Runtime Error?

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

數據結構實驗之二叉樹七:葉子問題

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

Problem Description

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

Input

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

Output

按從上到下從左到右的順序輸出二叉樹的葉子結點。

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

數據結構實驗之二叉樹五:層序遍歷

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

Problem Description

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

Input

輸入數據有多行,第一行是一個整數t?(t<1000),代表有t行測試數據。每行是一個長度小于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//按先序建立二叉樹,要是按照中序后序的順序自己應該會會寫出{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 ****************************************************/

總結

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

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