二叉树的三种遍历方式(递归)先根中根后根 二叉树的三种遍历方式(递归) 先根 1void preOrder(BinTree tree){2 if(tree == NULL){3 return ;4 }5 visit(tree);6 preOrder(tree->leftNode);7 preOrde ...
分类:
其他好文 时间:
2021-04-27 15:06:19
阅读次数:
0
#include <stdio.h> typedef struct Node { int data; struct Node* lchild; struct Node* rchild; }Node; typedef Node* BinTree; int array[] = {1,2,3,4,5,6, ...
分类:
编程语言 时间:
2020-11-27 10:52:16
阅读次数:
17
本题要求实现给定二叉搜索树的5种常用操作。 函数接口定义: BinTree Insert( BinTree BST, ElementType X ); BinTree Delete( BinTree BST, ElementType X ); Position Find( BinTree BST, ...
分类:
其他好文 时间:
2020-08-02 17:35:53
阅读次数:
103
输出二叉树中的叶子结点 void PreOrderPrintLeaves( BinTree BT ) { if( BT ) { if ( !BT-Left && !BT->Right )// 在二叉树的遍历算法中增加检测结点的“左右子树是否都为空”。 printf(“%d”, BT->Data ); ...
分类:
其他好文 时间:
2020-07-15 15:28:16
阅读次数:
72
1 Position Find(BinTree BST, ElementType X) { 2 if (!BST) return NULL;//查找失败 3 if (X > BST->Data) return Find(X, BST->Right);//在右子树中继续 4 else if (X < ...
分类:
其他好文 时间:
2020-06-29 00:32:28
阅读次数:
93
/*层次遍历,其实就是一个队列,先把根节点压入,之后进入循环,每次先弹出一个根节点,在输出值后,将其左右子树分别压入队列*/ void InorderTraversal(BinTree BT) { BinTree T; Stack S = CreateStack(100);//创建并初始化堆栈 wh ...
分类:
其他好文 时间:
2020-05-08 09:25:03
阅读次数:
66
数据结构13—二叉搜索树,堆 二叉树 二叉树的定义 1. Binode的模版——递归定义法 2. Binode接口实现 3. BinTree模版 二叉搜索树 二叉搜索树search 测试用例举例: [4,2,7,1,3] 2 二叉搜索树的插入 递归 此递归代码和老师讲的稍微有所不同,需要返回的是整个 ...
分类:
其他好文 时间:
2020-04-25 01:22:54
阅读次数:
94
BinTree Insert( BinTree BST, ElementType X ){ if(BST==NULL){ BST = (BinTree)malloc(sizeof(struct TNode)); BST->Left = NULL; BST->Right = NULL; BST->Da ...
分类:
其他好文 时间:
2020-03-30 21:49:44
阅读次数:
94
2.3二叉树的遍历 树的表示 1 //树的表示 2 typedef struct TreeNode *BinTree; 3 struct TreeNode 4 { 5 int Data;//存值 6 BinTree Left;//左儿子结点 7 BinTree Right;//右儿子结点 8 }; ...
分类:
其他好文 时间:
2020-03-28 13:17:09
阅读次数:
72
1 // #include <stdio.h> 2 // #include <stdlib.h> 3 4 // typedef char ElementType; 5 // typedef struct TNode *Position; 6 // typedef Position BinTree; ...
分类:
编程语言 时间:
2020-03-09 00:48:28
阅读次数:
125