树的先序,中序,后序递归遍历(链式存储结构)
来源:互联网 发布:海口Java招聘 编辑:程序博客网 时间:2024/06/06 02:58
#include <stdio.h>#include <malloc.h>#define DataType chartypedef struct Node{ DataType Data; struct Node *LeftChild; struct Node *RightChild;}BitNode,*BitTree; BitTree CreatTree(BitTree root); void PreOrder(BitTree root); void InOrder(BitTree root); void PostOrder(BitTree root); void VisitTree(BitTree root); BitTree CreatTree(BitTree root){ char ch; ch=getchar(); if('^'==ch) { root=NULL; } else { root=(BitTree)malloc(sizeof(BitNode)); root->Data=ch; root->LeftChild=CreatTree(root->LeftChild); root->RightChild=CreatTree(root->RightChild); } return root;} void PreOrder(BitTree root){ if(root) { VisitTree(root); PreOrder(root->LeftChild); PreOrder(root->RightChild); }}void InOrder(BitTree root){ if(root) { InOrder(root->LeftChild); VisitTree(root); InOrder(root->RightChild); }}void PostOrder(BitTree root){ if(root) { PostOrder(root->LeftChild); PostOrder(root->RightChild); VisitTree(root); }}void VisitTree(BitTree root){ printf("%c ",root->Data);} int main(void){ BitTree root=NULL; root=CreatTree(root); printf("The tree line traversal sequence :\n"); PreOrder(root); printf("\n"); printf("In order traversal sequence tree:\n"); InOrder(root); printf("\n"); printf("After the traversal sequence tree:\n"); PostOrder(root); printf("\n"); return 0;}
0 0
- 树的先序,中序,后序递归遍历(链式存储结构)
- C++实现链式二叉树,采用非递归的方式先序,中序,后序遍历二叉树
- 二叉树T 的先序遍历、中序遍历、后序遍历(递归实现)
- 二叉树的先序/中序/后序(递归、非递归)+层序遍历
- 二叉树的先序、中序、后序遍历(递归 and 非递归)
- 二叉树的先序、中序、后序递归遍历和非递归遍历
- 二叉树的遍历(2)--先序遍历,中序遍历,后序遍历(非递归)
- [转载]树的先序遍历,中序遍历,后序遍历的非递归写法
- 算法学习 - 树的三种遍历(递归实现)先序遍历,中序遍历,后序遍历
- 二叉树(先序创建,递归先序,中序,后序遍历)-----1
- c++实现二叉树的先序遍历,中序遍历,后序遍历(递归方法)
- 二叉树的非递归遍历(先序,中序,后序)
- 二叉树的非递归(先序、中序、后序)遍历
- 二叉树遍历的非递归算法(先序、中序、后序)代码实现
- 二叉树的递归遍历(先序、中序、后序)
- 二叉树的先序-中序-后序遍历(一)-递归
- 二叉树的遍历(递归,先序,中序,后序)
- 二叉树的遍历(先序/中序/后序,递归/迭代)与搜索
- ecshop 结构
- Uip webserver数组数据分析
- JNI开发 api jni.h文件使用
- UIP webservise
- MapReduce中Shuffle过程整理
- 树的先序,中序,后序递归遍历(链式存储结构)
- Django新版添加app提示模块不存在解决方法 INSTALLED_APPS 错误
- ACM数学
- MyEclipse + Maven 整合时一些奇葩问题的解决办法
- Python WSGI 介绍
- ubuntu eclipse打开help-》install new software 等选项没反应的解决办法
- selenium Python自动化测试(基本的鼠标事件)
- 数论题目分类
- 9、数据库初学习,基本安装以及配置、使用方法