二叉树的重建(递归实现)
来源:互联网 发布:js 数组转字符串 编辑:程序博客网 时间:2024/05/22 01:15
由前序遍历和中序遍历输出后序遍历
<span style="color:#000000;">#include<stdio.h>#include<string.h>void print_build(int n, char*s1, char* s2){ if(n <= 0) return ; int p = strchr(s2, s1[0])-s2; print_build(p, s1+1, s2); print_build(n-p-1, s1+p+1, s2+p+1); printf("%c",s1[0]);}int main(){ char s1[20],s2[20]; while(~scanf("%s%s",s1, s2))/*输入前序遍历和中序遍历*/ { int n = strlen(s1); print_build(n, s1, s2); printf("\n"); } return 0;}</span>
有后序遍历和中序遍历输出前序遍历
<span style="color:#000000;">#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;void print_build(int n, char* s1, char* s2){ if(n<=0) return ; printf("%c",s1[0]); int p = strchr(s2,s1[0])-s2; print_build(p, s1+n-p, s2); print_build(n-p-1,s1+1,s2+p+1);} int main(){ char s1[20],s2[20]; while(~scanf("%s%s",s1,s2))/*输入后序遍历和中序遍历*/ { int n = strlen(s1); reverse(s1,s1+n); print_build(n, s1, s2); printf("\n"); } return 0;}</span>
0 0
- 二叉树的重建(递归实现)
- 重建二叉树(C++递归实现)
- 重建二叉树:递归
- 递归重建二叉树的思路
- 二叉树的遍历;前序 中序 后序遍历二叉树;递归 非递归实现; 重建二叉树;编程之美重建二叉树
- 二叉树的遍历以及重建(Python实现)
- 二叉树的非递归遍历与重建
- 重建二叉树(字符串操作实现)
- 重建二叉树(链表实现)
- 【剑指offer】重建二叉树&&二叉树的递归与非递归遍历
- 二叉树的遍历(递归实现+非递归实现)
- 编程之美之重建二叉树(递归的解法)
- 二叉树的重建
- 二叉树的重建!!!
- 二叉树的重建
- 二叉树的重建
- 二叉树的重建
- 二叉树的重建
- Socket UDP无连接通信
- Zoj 3811 Untrusted Patrol 求连通顺序
- C++面试题5:建议在函数里面不要用sizeof算数组的大小
- 数据结构---单链表
- C++面试题6:sizeof 使用规则及陷阱
- 二叉树的重建(递归实现)
- 可以学习的计算机书籍
- json的简单介绍
- Codeforces Round #265 (Div. 1) A
- 嵌入式C51编程规范
- 【ACdream】1070 神奇的%系列二
- 黑马程序员——java小结_002_String类
- Mark-and-Sweep Garbage Collection
- zoj 3818 Pretty Poem (模拟)