UVA 536 Tree Recovery (先加中建树)
来源:互联网 发布:怎么增强手机网络 编辑:程序博客网 时间:2024/05/06 14:47
分析:类似上一篇博客
#include <cstdio>#include <iostream>#include <cstring>#include <algorithm>using namespace std;const int maxn=30;struct Node{ char data; struct Node *left,*right;};struct Node node[maxn];char xianxu[maxn],zhongxu[maxn];int nodeindex=0;struct Node *NewNode(){ node[nodeindex].left=NULL; node[nodeindex].right=NULL; return &node[nodeindex++];};struct Node* CreateTree(char *xianxu,char *zhongxu,int len)//先和中建树{ if (len==0) return NULL; int k=0; while (zhongxu[k]!=xianxu[0]) k++; struct Node *h=NewNode(); h->data=xianxu[0]; h->left=CreateTree(xianxu+1,zhongxu,k); h->right=CreateTree(xianxu+k+1,zhongxu+k+1,len-k-1); return h;};void houbian(Node *root)//后序遍历{ if (root) { houbian(root->left); houbian(root->right); printf("%c",root->data); }}int main(){ while (scanf("%s",xianxu)!=EOF) { nodeindex=0; scanf("%s",zhongxu); int len=strlen(xianxu); struct Node *root=CreateTree(xianxu,zhongxu,len); houbian(root); printf("\n"); } return 0;}
0 0
- UVA 536 Tree Recovery (先加中建树)
- UVA 536 - Tree Recovery
- uva 536Tree Recovery
- uva 536 - Tree Recovery
- UVA 536 Tree Recovery
- UVA 536 Tree Recovery
- UVa, 536 Tree Recovery
- uva 536 - Tree Recovery
- UVa 536 - Tree Recovery
- UVA - 536 Tree Recovery
- UVa 536 Tree Recovery
- UVa 536 - Tree Recovery
- UVA - 536 Tree Recovery
- Uva - 536 - Tree Recovery
- Tree Recovery-UVA 536
- uva 536 - Tree Recovery
- Uva-536 Tree Recovery
- UVA - 536 Tree Recovery
- 博客说明
- 去除百度地图左下角标注
- 【HBOI2013】ALO
- POJ1018 Communication System(DP||贪心)
- 免密码登陆服务器
- UVA 536 Tree Recovery (先加中建树)
- 什么是ARP/RARP?
- 欢迎使用CSDN-markdown编辑器
- 二叉树
- 在一亿个数中查找最大的k个数(k << 1,000,000,000)
- struts2中的constant配置详解
- Perl6 -1.0 安装与运行
- HI3518E交叉编译环境搭建
- jquery中eq和get (