【输出二叉树中的叶子结点】无论前序、中序、后序遍历,叶子结点的输出顺序都是一样的吗?都是一样的,输出顺序为:从树的左边到右边叶子!!在二叉树的遍历算法中增加检测结点的“左右子树是否都为空”。 1 void PreOrderPrintLeaves(BinTree Bt) 2 { 3 if(Bt...
分类:
其他好文 时间:
2015-02-04 16:30:34
阅读次数:
198
【先序遍历】先序遍历的过程为:访问“根结点”;“先序”遍历其“左子树”;“先序”遍历其“右子树”;1 void PreOrderTraversal( BinTree BT )2 {3 if( BT )4 {5 printf(“%d”, BT->Data);6 ...
分类:
其他好文 时间:
2015-01-29 11:58:31
阅读次数:
150
1 void postOrder3(BinTree *root) //非递归后序遍历 2 { 3 stack s; 4 BinTree *cur; //当前结点 5 BinTree *pre=NULL; ...
分类:
其他好文 时间:
2015-01-20 08:56:05
阅读次数:
243
二叉搜索树的删除:
在删除之前需要从树中查找到这个节点,然后再针对情况来判断如何删除。
分为三种情况,首先是此节点没有孩子节点,此节点有一个孩子节点,此节点有两个孩子节点
void Delete(BinTree*& root,int value)
{
BinTree* delnode= NULL;
if(root == NULL)
return ;
BinTree* temp ...
分类:
其他好文 时间:
2015-01-19 10:52:53
阅读次数:
121
二叉搜索树:动态查找a.非空左子树的所有值小于其根接点值b.非空右子树的所有值大于其根接点值c.左、右子树均为二叉搜索树Position Find( ElementType X, BinTree BST ):从二叉搜索树BST中查找元素X,返回其所在结点的地址Position FindMin( Bi...
分类:
其他好文 时间:
2014-12-28 11:41:26
阅读次数:
128
#include
#include
#include
using namespace std;
struct BinTree {
int data;
struct BinTree *left;
struct BinTree *right;
};
struct BinPost {
BinTree *pTree;
bool isFirst;
};
...
分类:
其他好文 时间:
2014-10-30 22:45:09
阅读次数:
207
如图:
代码:
#include
#include
#include
#include
using namespace std;
char ch;
typedef struct BinNode
{
char data;
struct BinNode *lchild,*rchild;
}BinNode,*BinTree; //二叉树链式...
分类:
其他好文 时间:
2014-06-05 09:15:24
阅读次数:
203