#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;
}

数据结构实验之二叉树二:遍历二叉树 SDUT 3341的更多相关文章

  1. 数据结构实验之排序二:交换排序 (SDUT 3399)

    #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; ...

  2. 数据结构实验之查找二:平衡二叉树 (SDUT 3374)

    #include <stdio.h> #include <string.h> #include <stdlib.h> struct node { int data; ...

  3. SDUT 2142 数据结构实验之图论二:基于邻接表的广度优先搜索遍历

    数据结构实验之图论二:基于邻接表的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Descript ...

  4. SDUT OJ 数据结构实验之链表二:逆序建立链表

    数据结构实验之链表二:逆序建立链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...

  5. SDUT OJ 数据结构实验之串二:字符串匹配

    数据结构实验之串二:字符串匹配 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  6. SDUT OJ 数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...

  7. SDUT 3399 数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 冒泡排序和快 ...

  8. SDUT 3374 数据结构实验之查找二:平衡二叉树

    数据结构实验之查找二:平衡二叉树 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 根据给定的输 ...

  9. SDUT-2117_数据结构实验之链表二:逆序建立链表

    数据结构实验之链表二:逆序建立链表 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 输入整数个数N,再输入N个整数,按照 ...

  10. SDUT-3399_数据结构实验之排序二:交换排序

    数据结构实验之排序二:交换排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 冒泡排序和快速排序都是基于"交 ...

随机推荐

  1. XML和JSON序列化以及反序列化

    1.将文件保存序列化至文档中,然后再读取: //首先创建可序列化的实体类 [Serializable] public class Message { public string Name { get; ...

  2. Linq to sql之left join运用示例

    示例一: var l= from a in cardsBll.GetCards() join b in usersBll.GetAllUsers() on a.CardSn equals b.Card ...

  3. openmp 和 thread 性能实测

    #include <stdio.h> #include <iostream> #include <thread> #include<omp.h> //# ...

  4. 基于vue的购物车清单

    <!doctype html> <html> <head> <meta charset="utf-8"> <link rel= ...

  5. leetcode-64. 最小路径和 · vector + DP

    题面 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right wh ...

  6. List · leetcode-24. 交换相邻节点

    题面 Given a linked list, swap every two adjacent nodes and return its head. You may not modify the va ...

  7. js 小细节(持续更新)

    1.在对数据进行操作时,一定要考虑数据里面每一个value值是否存在 $.each(data, function(i, item){ if(item == null || item.firstFram ...

  8. 《深入Linux内核架构》笔记 --- 第一章 简介和概述

    Linux将虚拟地址空间划分为两个部分,分别称为内核空间和用户空间 各个系统进程的用户空间是完全彼此分离的,而虚拟地址空间顶部的内核空间总是同样的,无论当前执行的是哪个进程. 尽管Intel处理器区分 ...

  9. NoNodeAvailableException[None of the configured nodes are available:

    elasticSearch的错误 NoNodeAvailableException[None of the configured nodes are available: [{#transport#- ...

  10. 服务器IP与个人IP的特点

    服务器IP:系统类型.开放的端口及运行的服务.C段同类机器数量.是否机房.IDC服务商 个人IP:系统类型.开放的端口及运行的服务……