国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

sdutacm-求二叉樹的先序遍歷

2019-11-06 06:48:09
字體:
來源:轉載
供稿:網友

求二叉樹的先序遍歷

TimeLimit: 1000MS Memory Limit: 65536KB

SubmitStatistic

PRoblem Description

 已知一棵二叉樹的中序遍歷和后序遍歷,求二叉樹的先序遍歷

Input

 輸入數據有多組,第一行是一個整數t (t<1000),代表有t組測試數據。每組包括兩個長度小于50的字符串,第一個字符串表示二叉樹的中序遍歷序列,第二個字符串表示二叉樹的后序遍歷序列。 

Output

 輸出二叉樹的先序遍歷序列

Example Input

2

dbgeafc

dgebfca

lnixu

linux

Example Output

abdegcf

xnliu

Hint

 

Author

 GYX

#include<string.h>#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<queue>#include<iostream>using namespace std;typedef struct node{   char data;   struct node*l;   struct node*r;}tree;void huifu(char *zhong,char *hou,int len){  if(len==0)  return ;  tree *p = new tree;  p->data = *(hou+len-1);  int i = 0;  for(;i<len;i++)  if(zhong[i]==*(hou+len-1))  {     break;  }   cout<<p->data;  huifu(zhong,hou,i);  huifu(zhong+i+1,hou+i,len-i-1);  return ;}int main(){   char hou[102],zhong[102];   int o;   cin>>o;   while(o--)   {    int i,len;   scanf("%s%s",zhong,hou);   len = strlen(hou);   huifu(zhong,hou,len);   cout<<endl;   }}/***************************************************User name: jk160505徐紅博Result: AcceptedTake time: 0msTake Memory: 156KBSubmit time: 2017-02-07 15:20:58****************************************************/


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江西省| 松原市| 朝阳区| 额济纳旗| 南华县| 千阳县| 保靖县| 扬中市| 融水| 连州市| 阿坝| 广昌县| 洪雅县| 石河子市| 阳西县| 岳阳县| 定远县| 和顺县| 黑河市| 岑巩县| 繁昌县| 榆中县| 镇巴县| 漯河市| 东乌珠穆沁旗| 油尖旺区| 宜州市| 如皋市| 兰考县| 临沧市| 乐亭县| 诸暨市| 高州市| 丽江市| 滨海县| 读书| 漳州市| 寿光市| 渭源县| 建平县| 宝丰县|