二叉树的遍历。。。
来源:互联网 发布:网络的英文翻译 编辑:程序博客网 时间:2024/06/05 14:44
#define LENGTH 100#include<stdio.h>#include<stdlib.h>typedef char datatype;//定义结构体typedef struct tree{ datatype data; struct tree * lchild; struct tree * rchild;}Tree, *Binary_Tree;//创建二叉树int ReadBinTree(Binary_Tree &t){ datatype data; scanf("%c",&data); if(data == '#'){ t = NULL; } else{ t = (Binary_Tree)malloc(sizeof(Tree)); //生成根结点 t->data = data; //构造左子树 ReadBinTree(t->lchild); //构造右子树 ReadBinTree(t->rchild); } return 0;}//输出void Visit(Binary_Tree t){ if(t->data != '#'){ printf("%c ",t->data); }}//先序遍历void preorder(Binary_Tree t){ if(t != NULL){ Visit(t); preorder(t->lchild); preorder(t->rchild); }}//中序遍历void inorder(Binary_Tree t){ if(t != NULL){ inorder(t->lchild); Visit(t); inorder(t->rchild); }}//后序遍历void epilogue(Binary_Tree t){ if(t != NULL){ epilogue(t->lchild); epilogue(t->rchild); Visit(t); }}int main(){ Binary_Tree t; printf("请输入:"); ReadBinTree(t); printf("先序遍历:\n"); preorder(t); printf("\n"); printf("中序遍历:\n"); inorder(t); printf("\n"); printf("后序遍历:\n"); epilogue(t); printf("\n"); return 0;}
0 0
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- 二叉树的遍历
- Leetcode-maximum-depth-of-binary-tree
- Eclipse插件springsource-tool-suite的下载和安装
- 学习 Promise (结合 Rxjava)
- Leetcode-reverse-integer
- Two Cylinders (辛普森公式处理积分)
- 二叉树的遍历。。。
- BZOJ 2208: [Jsoi2010]连通数
- 4. gpio 库
- Android Studio NDK调试(基于gradle-experimental插件与LLDB)
- jquery 基础
- Linux内核模块编译
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的解决办法
- Android: 动画实现雷达效果
- 静态函数为什么不能是虚函数?