上代码(创建树,先序,中序,后序)

#include<bits/stdc++.h>
using namespace std;
typedef struct TreeNode *BinTree;
struct TreeNode
{BinTree left,right;int value;
};
BinTree CreateTree()
{BinTree T;int value;cin>>value;if(value==0)        //如果输入0,则创建树停止{T=NULL;}else{T=(BinTree)malloc(sizeof(TreeNode));T->value=value;T->left=CreateTree();T->right=CreateTree();}return T;
}
void Preorder(BinTree T)//Preorder Traversal,root first,left-child second,right-child third.
{if(T==NULL){return;}cout<<T->value<<endl;Preorder(T->left);Preorder(T->right);return;
}
void Inorder(BinTree T)//Inorder Traversa,left-child first,root second,right-child third.
{if(T==NULL){return;}Inorder(T->left);cout<<T->value<<endl;Inorder(T->right);return ;
}
void Postorder(BinTree T)//Postorder Traversal,left-child first,right-child second,root third.
{if(T==NULL){return ;}Postorder(T->left);Postorder(T->right);cout<<T->value<<endl;return ;
}
int main()
{BinTree root;root=CreateTree();Preorder(root);Inorder(root);Postorder(root);return 0;
}

代码暂不做解释,留个人参考使用.
 
 
测试数据:
input:
1 2 4 0 0 5 0 0 3 0 0

output:
1 2 4 5 3
4 2 5 1 3
4 5 2 3 1
(将换行更改一下)

树的遍历-Preorde Traversal,Inorder Traversal,Postoder Traversal相关推荐

  1. 数据结构思维 第六章 树的遍历

    第六章 树的遍历 原文:Chapter 6 Tree traversal 译者:飞龙 协议:CC BY-NC-SA 4.0 自豪地采用谷歌翻译 本章将介绍一个 Web 搜索引擎,我们将在本书其余部分开 ...

  2. tree traversal (树的遍历) - inorder traversal (中序遍历)

    tree traversal (树的遍历) - inorder traversal (中序遍历) 1. tree traversal - 树的遍历 二叉树的遍历 (traversing binary ...

  3. tree traversal (树的遍历) - postorder traversal (后序遍历)

    tree traversal (树的遍历) - postorder traversal (后序遍历) 1. tree traversal - 树的遍历 二叉树的遍历 (traversing binar ...

  4. tree traversal (树的遍历) - preorder traversal (前序遍历)

    tree traversal (树的遍历) - preorder traversal (前序遍历) 1. tree traversal - 树的遍历 二叉树的遍历 (traversing binary ...

  5. tree traversal (树的遍历) - 层序遍历 (level order traversal) - 二叉树的层序遍历

    tree traversal (树的遍历) - 层序遍历 (level order traversal) - 二叉树的层序遍历 1. tree traversal (树的遍历) 1.1 深度优先搜索 ...

  6. Construct Binary Tree from Inorder and Postorder Traversal

    题目 Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume ...

  7. LeetCode - 106 - Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  8. 【LeetCode】106. Construct Binary Tree from Inorder and Postorder Traversal

    Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...

  9. leetcode 刷题之路 64 Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

最新文章

  1. vbscript错误代码及对应解释大全[z]
  2. 斯坦福大学深度学习与自然语言处理第一讲引言
  3. PE 学习之路 —— 区块表
  4. 移动spa商城优化记(一)---首屏优化篇
  5. 加速ASP.NET Core WEB API应用程序——第2部分
  6. 李开复对谈硅谷传奇:杨致远敦促AI交产品,马尔科夫说无人车3年没戏
  7. js 小数自动补0_JS自定义保留小数,并支持补零(四舍五入)
  8. Contains Duplicate 包含重复值
  9. 易语言代码转php,易语言代码转PHP代码有没大佬
  10. 数值计算之 梯度向量和梯度矩阵,雅可比矩阵,海森矩阵
  11. 整理wind商誉数据2016-2019
  12. 通过日期的相减计算年龄
  13. 一键式免费借还的智能充电宝租赁
  14. 电脑卡顿?性能不足?一套连招榨干你的电脑!
  15. 永琳的竹林迷径(path)
  16. 恒生电子股份有限公司--软件测试--《社招、校招jd、校招行程,招聘动态》整理
  17. 少儿编程课程体系需求
  18. authorize(权限验证)
  19. 【带你看看开源圈的新趋势】GITHUB OCTOVERSE 2022 详细解读
  20. 我的Java学习感悟

热门文章

  1. SAP 那点事BW HANA
  2. VC6下使用WebLink控件
  3. Docker中安装Jenkins实时发布.net core 项目(一)
  4. 注册机patch起什么作用_电机滑环起什么作用?
  5. $.each()、$.map()区别浅谈
  6. php查询数据方法,php查询数据库的方法
  7. sqlserver note
  8. 1004 成绩排名 (20分)
  9. JQuery 中选择多选择框,和单选框,实现获取相应选择的值
  10. 13 python初学(函数)