数据结构实验之二叉树二:遍历二叉树 SDUT 3341
2024-09-05 04:22:16
#include <bits/stdc++.h>
using namespace std;
struct Tree
{
char data;
struct Tree *right;
struct Tree *left;
};
char str[55];
int num;
struct Tree *creat()
{
struct Tree * root;
if(str[num ++] == ',')
{
root = NULL;
}
else
{
root = (struct Tree *)malloc(sizeof(struct Tree));
root -> data = str[num - 1];
root -> left = creat();
root -> right = creat();
}
return root;
}
void inorder(struct Tree * root)
{
if(root)
{
inorder(root -> left);
printf("%c", root -> data);
inorder(root -> right);
}
}
void postorder(struct Tree * root)
{
if(root)
{
postorder(root -> left);
postorder(root -> right);
printf("%c", root -> data);
}
}
int main()
{
while(~scanf("%s",str))
{
num = 0;
struct Tree * root;
root = creat();
inorder(root);
printf("\n");
postorder(root);
printf("\n");
}
return 0;
}
最新文章
- MongoDB索引
- .Net的内置对象之一 Request
- Eclipse启动tomcat,http://localhost:8080/无法访问的解决方法
- 微信小程序-媒体组件
- java对txt文件内容追加
- web服务器安装配置
- Codeforces Round #131 (Div. 1) B. Numbers dp
- MyEclipse2015 编写js报 &#39;Calculating completion proposals..&#39; has encountered a problem.
- Unix编程之size_t、ssize_t
- AngularJS 学习随笔(一)
- WVGA-维基百科
- sgu 101 domino
- 回收进程用户空间资源 exit()函数 _exit()函数 atexit()函数 on_exit()函数
- Bluetooth 2.1+EDR是什么
- MySQL FEDERATED 存储引擎
- jquery-ui-multiselect 的使用
- Node.js 子进程
- git版本控制工具的使用
- mybatis入门篇:Mybatis注解方式的基本用法
- bzoj2190
热门文章
- LeetCode 1047. Remove All Adjacent Duplicates In String
- Android蓝牙遥控器APP关键代码 guihub项目
- 微软升级 WSL Window Subsystem for Linux Win10系统自带Linux
- css手册中各种符号的意思
- JavaScript--常用对象的属性及方法(2)
- ES6 class 于 继承 extends
- SAP Marketing Cloud的Contact导入配置和数据合并原理
- Java实现 Cookie的生成与读取
- YII2 实现dropDownList 联动事件
- dockerfile构建nginx