
树
快活书生
人生就像一次星际旅行,旅途中会遇到很多耀眼的星星,你可以选择努力与摘下一颗耀眼的明星,虽然这颗明星代表不了你的一生,但你的星途会因为那些你努力摘下的星星而更加璀璨!
展开
-
L3-010 是否完全二叉搜索树(30 分)
7-2 是否完全二叉搜索树(30 分)将一系列给定数字顺序插入一个初始为空的二叉搜索树(定义为左子树键值大,右子树键值小),你需要判断最后的树是否一棵完全二叉树,并且给出其层序遍历的结果。 输入格式:输入第一行给出一个不超过20的正整数N;第二行给出N个互不相同的正整数,其间以空格分隔。 输出格式:将输入的N个正整数顺序插入一个初始为空的二叉搜索树。在第一行中输出结果树的层序遍历结果,数字间以1原创 2017-10-28 11:03:55 · 1135 阅读 · 0 评论 -
1123 Is It a Complete AVL Tree(AVL树)
标明出处:https://www.liuchuo.net/archives/27321123 Is It a Complete AVL Tree(30 分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node ...转载 2018-09-07 19:31:36 · 170 阅读 · 0 评论 -
二叉树数叶子,计算树高
int CountLeaf(BiTree T){ if(T == NULL) return 0; if(T->lchild == NULL && T->rchild == NULL) return 1; else{ n1 = CountLeaf(T->lchild); n2 = CountLeaf(T->rchild);原创 2018-01-28 11:43:54 · 507 阅读 · 0 评论 -
二叉树的遍历(25 分)
#include <stdio.h>#include <stdlib.h>typedef char ElementType;typedef struct TNode *Position;typedef Position BinTree;struct TNode{ ElementType Data; BinTree Left; BinTree Right;};BinT原创 2017-11-14 12:37:37 · 1280 阅读 · 0 评论 -
二叉搜索树的操作集(30 分)
#include <stdio.h>#include <stdlib.h>typedef int ElementType;typedef struct TNode *Position;typedef Position BinTree;struct TNode{ ElementType Data; BinTree Left; BinTree Right;};void原创 2017-11-09 21:00:42 · 333 阅读 · 0 评论 -
二叉树三种遍历(递归的妙用)
先序遍历void preorder(Tree r){ if(r){ printf("%c ",r->data); preorder(r->l); preorder(r->r); } }后序遍历void postorder(Tree r){ if(r){ preorder(r->l原创 2017-11-02 19:28:25 · 266 阅读 · 0 评论 -
1138 Postorder Traversal(二叉树前序中序转后序)
1138 Postorder Traversal(25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the preorder and inorder traversal sequences, you are supposed to output the first numb...原创 2018-08-14 08:54:12 · 195 阅读 · 0 评论 -
最小生成树(Kruskal)
#include<iostream>#include<algorithm>using namespace std;int pre[100];struct edge{ int u,v,w;}edge[100];bool cmp(struct edge a,struct edge b){ return a.w<b.w;}int findf(int x){ int原创 2017-08-12 15:11:51 · 189 阅读 · 0 评论 -
最小生成树(Prim)
#include<iostream>using namespace std;#define INFINITE 9999;int e[100][100];int main(){ int i,j,k,w;//得到图(邻接矩阵) int n,m; int sum=0; int cnt=0; int mins=INFINITE; int min_ind原创 2017-08-12 18:22:49 · 215 阅读 · 0 评论 -
二叉树
#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;vector&gt;#include &lt;cstring&gt;#include &lt;queue&gt;#include&lt;stack&gt;#include&原创 2017-10-27 17:09:46 · 166 阅读 · 0 评论 -
求二叉树的叶子结点个数(前序建立二叉树)
7-7 求二叉树的叶子结点个数(20 分)以二叉链表作为二叉树的存储结构,求二叉树的叶子结点个数。 输入格式:输入二叉树的先序序列。提示:一棵二叉树的先序序列是一个字符串,若字符是‘#’,表示该二叉树是空树,否则该字符是相应结点的数据元素。 输出格式:输出有两行:第一行是二叉树的中序遍历序列;第二行是二叉树的叶子结点个数。 输入样例:ABC##DE#G##F### 输出样例:CBEGDFA3原创 2017-10-27 19:55:46 · 2640 阅读 · 0 评论 -
讲解前序中序建立二叉树
vector版:直接上c++代码,讲解在下面,一定要看哦!struct node{ node *l, *r; int val; node(int x) : val(x), l(NULL), r(NULL) {}};node* reBuild(vector&lt;int&gt; pre, vector&lt;int&gt; in){ vector&lt;int...原创 2018-09-12 20:11:41 · 1185 阅读 · 0 评论