二叉树遍历
来源:互联网 发布:别斯兰人质事件知乎 编辑:程序博客网 时间:2024/06/05 23:39
#include<stdio.h>#define maxsize 50struct bittree{int data;bittree *lchild, *rchild;};//使用递归的先序,中序以及后序遍历void visit(bittree *t){printf("%d\n", t->data);}void preorder(bittree *t){if (t != NULL){visit(t);preorder(t->lchild);preorder(t->rchild);}}void inorder(bittree *t){if (t!=NULL){inorder(t->lchild);visit(t);inorder(t->rchild);}}void postorder(bittree *t){if (t != NULL){postorder(t->lchild);postorder(t->rchild);visit(t);}}void inorder2(bittree *t){initstack(s);bittree *p = t;while (p || !isempty(s)){if (p){push(s, p);p = p->lchild;}else{pop(s, p);visit(p);p = p->rchild;}}}//层次遍历void leveorder(bittree *t){initqueue(q);bittree *p;enqueue(q, t);while (!isempty(q)){dequeu(q, p);}visit(p);if (p->lchild!==NULL){enqueue(q, p->lchild);}if (p->rchild != NULL){enqueue(q, p->rchild);}}
0 0
- 二叉树遍历、分层遍历
- 遍历二叉树--二叉树
- 【树】遍历二叉树
- 二叉树遍历
- 二叉树遍历
- 二叉树的遍历
- (原创)遍历二叉树
- 二叉树遍历-php
- 查找--遍历二叉树
- 遍历二叉树
- 二叉树遍历规则
- 二叉树的遍历
- 二叉树遍历
- 遍历二叉树
- 二叉树遍历问题
- 二叉树遍历
- 二叉树遍历(zz)
- 二叉树的遍历
- 当数组过大时的排序问题
- 深入浅出——网络模型中Inception的作用与结构全解析
- 计算机类中文核心期刊简介
- 牛课网--直通BAT面试算法精讲课--送优惠码啦
- Leetcode -- 491. Increasing Subsequences
- 二叉树遍历
- 【phpMyAdmin】Linux下安装phpmyadmin
- ubuntu安装 arm-linux-gcc-4.4.3
- c语言_删除数组中的重复数据
- jQuery.grep()
- Io流运用1
- opencv:图像的载入、显示以及创建窗口
- BS8116A-3驱动程序(使用STM32--STM32cubemx)
- spring Data Jpa 相关