二叉树&搜索树&平衡树
二叉树&搜索树&平衡树;
-Hello_狂奔的蜗牛
Fly!!!
展开
-
递归实现二叉树的三种遍历
#include #include typedef char ElementType;typedef struct TreeNode *BinTree;struct TreeNode{ElementType Data;BinTree lchild;BinTree rchild;};//建立 void creatBinTree(BinTree *T){原创 2016-11-15 14:47:27 · 407 阅读 · 0 评论 -
伸展树(一)之 图文解析 和 C语言的实现
概要本章介绍伸展树。它和"二叉查找树"和"AVL树"一样,都是特殊的二叉树。在了解了"二叉查找树"和"AVL树"之后,学习伸展树是一件相当容易的事情。和以往一样,本文会先对伸展树的理论知识进行简单介绍,然后给出C语言的实现。后序再分别给出C++和Java版本的实现;这3种实现方式的原理都一样,选择其中之一进行了解即可。若文章有错误或不足的地方,希望您能不吝指出!目录1. 伸展树的介绍转载 2017-08-03 10:58:08 · 293 阅读 · 0 评论 -
Java, c++ 中序和前序 或 中序和后序构建二叉树
利用递归,构建二叉树的时候主要就是要搞清楚,前序和中序,后序与中序的关系,然后要递归地往下构建,先建当前节点的左孩子,再右孩子,然后我利用另外一种序列遍历来验证 构建的二叉树是否正确。#include <iostream>#include <cstdio>using namespace std;const int maxn = 35;int in[maxn];int pre[maxn];原创 2017-07-31 10:10:00 · 620 阅读 · 0 评论 -
Java 初始化二叉树,先序,中序,后序遍历,深度
import java.util.Scanner;//定义二叉树结点类型class CBTType { String data;//元素数据 CBTType left; CBTType right;}class Main { static final int MAXLEN = 20; static Scanner input = new Scanner原创 2017-06-10 17:09:10 · 1004 阅读 · 0 评论 -
前序和中序建树,后序和中序建树
利用递归,构建二叉树的时候主要就是要搞清楚,前序和中序,后序与中序的关系,然后要递归地往下构建,先建当前节点的左孩子,再右孩子,然后我利用另外一种序列遍历来验证 构建的二叉树是否正确。#include <iostream>#include <cstdio>using namespace std;const int maxn = 35;int in[maxn];int pre[maxn];原创 2017-05-09 18:06:27 · 1117 阅读 · 0 评论 -
先序和中序求后序,后序和中序求先序
//preorder and postorder,先序和中序求后序#include <cstdio>#include <iostream>using namespace std;void getpost(int *pre, int *in, int n) { if(n == 0) return; int root = pre[0]; int i;原创 2016-11-29 06:59:26 · 737 阅读 · 1 评论 -
递归实现二叉树的三种遍历
#include <stdio.h>#include <stdlib.h>typedef char ElementType;typedef struct TreeNode *BinTree;struct TreeNode{ElementType Data;BinTree lchild;BinTree rchild;};//建立 void creatBinTree(BinTree原创 2016-12-10 10:26:09 · 404 阅读 · 0 评论 -
BST二叉搜索树的查找,最大小值,删除,插入
#include <cstdio>#include <cstdlib>#include <queue>using namespace std;typedef struct TreeNode* BinTree;typedef int ElementType;//以int为例 typedef BinTree Position;struct TreeNode{ ElementTyp原创 2016-11-17 09:52:49 · 1253 阅读 · 0 评论 -
层序生成二叉树和层序遍历
#include <cstdio>#include <cstdlib>#include <queue>using namespace std;typedef struct TreeNode* BinTree;typedef int ElementType;//以int为例 typedef BinTree Position;struct TreeNode{ ElementTyp原创 2016-11-17 09:14:13 · 771 阅读 · 4 评论 -
非递归实现二叉树三种遍历
#include <cstdio>#include <cstdlib>#include <stack>using namespace std;typedef char ElementType;typedef struct TreeNode* BinTree;struct TreeNode{ ElementType Data; BinTree lchild; Bi原创 2016-11-16 19:41:44 · 377 阅读 · 0 评论 -
二叉树的叶结点和高度
#include #include #include using namespace std;typedef char ElementType;typedef struct TreeNode *BinTree;struct TreeNode{ElementType Data;BinTree lchild;BinTree rchild;};//建立 v原创 2016-11-15 19:18:10 · 809 阅读 · 0 评论 -
AVL树(一)之 图文解析 和 C语言的实现
概要本章介绍AVL树。和前面介绍"二叉查找树"的流程一样,本章先对AVL树的理论知识进行简单介绍,然后给出C语言的实现。本篇实现的二叉查找树是c语言版的,后面章节再分别给出C++和Java版本的实现。建议:若您对"二叉查找树"不熟悉,建议先学完"二叉查找树"再来学习AVL树。目录1. AVL树的介绍2. AVL树的C实现3. AVL树的C实现(完整源码)4. AVL树的转载 2017-08-03 10:56:31 · 543 阅读 · 0 评论