数据结构实验之二叉树二:遍历二叉树
来源:互联网 发布:毛利率算法 编辑:程序博客网 时间:2024/05/23 22:37
SDUT原题:点击打开链接
中序遍历:顾名思义就是先访问左子树,再访问根,最后访问右子树
后续遍历:先访问左子树,在访问右子树,最后访问根
这个序就是按照根的节点来排序的
#include <iostream>#include <stdlib.h>using namespace std;char ch[100];int cnt;struct node{ char data; struct node * lchild; struct node * rchild;};struct node * creat(){ struct node * root; if(ch[++cnt] == ',') root = NULL; else { root = (struct node * )malloc(sizeof(struct node)); root->data = ch[cnt]; root->lchild = creat(); root->rchild = creat(); } return root;};void zhongxu(struct node * root){ if(root) { zhongxu(root->lchild); cout << root->data; zhongxu(root->rchild); }}void houxu(struct node * root){ if(root) { houxu(root->lchild); houxu(root->rchild); cout << root->data; }}int main(){ struct node * root; while(cin >> ch) { cnt = -1; root = creat(); zhongxu(root); cout << endl; houxu(root); cout << endl; } return 0;}
0 0
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- SDUT3341数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 3341数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 数据结构实验之二叉树二:遍历二叉树
- 一心多用多线程-Thread的api探险
- 手把手教你解决Linux中根分区不足问题^^
- AndroidStudio报错 Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
- 悲观锁
- Spring 框架学习—控制反转(IOC)
- 数据结构实验之二叉树二:遍历二叉树
- Accellion File Transfer Appliance 弱點報告
- 《APUE》笔记-第四章-文件和目录
- 一文读懂卷积神经网络
- 使用java连接memcache服务器
- 函数定义命名空间的使用
- 语音群呼平台企业营销利器
- android自动化测试相关
- [系统设置] 还在为误关闭MTP(媒体设备)而现在手机连不上电脑烦恼?