数据结构-树-二叉树-定义,遍历
来源:互联网 发布:centos更改ip地址 编辑:程序博客网 时间:2024/06/04 20:46
//定义//二叉链表typedef struct btnode{DataType data;struct btnode *lchild,*rchild;}*BinTree;BinTree root;//三叉链表typedef struct ttnode{DataType data;struct ttnode *lchild,*parent,*rchild;}*TBinTree;TBinTree root;//遍历//先序void preorder(BinTree bt){if (bt!=NULL){visit(bt);preorder(bt->lchild);preorder(bt->rchild);}}//中序void inorder (BinTree bt){if(bt!=NULL){inorder(bt->lchild);visit(bt);inorder(bt->rchild);}}//后序void postorder(BinTree bt){if (bt!=NULL){postorder(bt->lchild);postorder(bt->rchild);visit(bt);}}//求深度int Height(BinTree bt){int lh,rt;if (bt==NULL)return 0;else{lh=height(bt->lchild);rh=Height(bt->rchild);return 1+(lh>rh ? lh:rh);}}//层次遍历void levelorder(BinTree bt){LkQue Q;InitQueue(&Q);if (bt!=NULL){EnQueue(&Q,bt);while (!EmptyQueue(Q)){p=Gethead(&Q);outQueue(&Q);visit(p);if(p->lchild!=NULL)EnQueue(&Q,p->lchild);if(p->rchild!=NULL)EnQueue(&Q,p->rchild);}}}//遍历-非递归,中序visit调到pop(LS)和p=p->rchild之间void PreOrder(BinTree t){BinTree p;LkStk *LS;if (t==NULL)return;InitStack (LS);p=t;while(p!=NULL||!EmptyStack(LS)){if (p!=NULL){visit(p->data);Push(LS,p);p=p->lchild}else{p=GetTop(LS);Pop(LS);p=p->rchild}}}
0 0
- 数据结构-树-二叉树-定义,遍历
- 二叉树遍历 - 数据结构
- 数据结构 二叉树遍历
- 数据结构 - 二叉树遍历
- 二叉树遍历 - 数据结构
- 数据结构--二叉树遍历
- 【数据结构】二叉树遍历
- 数据结构-二叉树遍历
- 数据结构--遍历二叉树
- 数据结构二叉树遍历
- 数据结构二叉树遍历
- 数据结构-二叉树定义
- 【数据结构】二叉树的定义,递归遍历,非递归遍历,层次遍历,深度等
- 数据结构 二叉树 创建 遍历
- 数据结构之二叉树遍历
- 数据结构 - 二叉树的遍历
- 数据结构-----二叉树的遍历
- 数据结构----二叉树的遍历
- android 事件分发伪代码
- javascript中的原型
- 用两台usb摄像头摄取的画面找surf匹配点
- JavaScript中原型对象的彻底理解
- (七)Spring详解——资源Resource接口
- 数据结构-树-二叉树-定义,遍历
- 跑马灯实验-位带操作版
- JSON
- C++变量的声明与定义
- 变量和存储区
- 大白话之设计模式--简单工厂模式理解记忆
- 让MFC不显示界面
- C语言递归与非递归实现求第n个斐波那契数
- 数据结构-树-定义,哈夫曼