树其实在本质上就是一对多,链表就是一对一。 二叉树的建立: 这里的代码采用的是最粗暴的创建方法,无实际用处。但初次学习二叉树可以通过这个创建方法更好的理解二叉树。 二叉树的遍历: 遍历在大体上分为递归遍历和非递归遍历。 遍历总共三种遍历顺序: 1.先序遍历:根,左,右 2.中序遍历:左,根,右 3. ...
分类:
编程语言 时间:
2020-02-01 00:49:01
阅读次数:
99
前言 树的遍历分为: 1.深度优先遍历 2.广度优先遍历 深度优先遍历: 1.前序遍历 2.中序遍历 3.广序遍历 广度优先遍历: 层序遍历 深度优先遍历 如图: 前序遍历 前序遍历的规则为:根节点、左子树、右子树 根据规则,第一个点即为根节点: 第一个为A。 A 有左子树:左子树的第一个节点又为左 ...
分类:
编程语言 时间:
2020-01-31 22:45:09
阅读次数:
95
1.递归 递归是一个函数直接或间接地调用自身,是为直接或间接递归。一般来说,递归需要有边界条件、递归前进段和递归返回段。当边界条件不满足时,递归前进;当边界条件满足时,递归返回。用递归需要注意以下两点: (1) 递归就是在过程或函数里调用自身。(2) 在使用递归策略时,必须有一个明确的递归结束条件, ...
分类:
其他好文 时间:
2020-01-29 17:53:12
阅读次数:
82
这次首先总结二叉树的前序、中序、后序、层次遍历的递归与非递归实现。下次总结二叉树的查找、求二叉树的深度、统计节点个数与节点比较的递归实现。二叉树的结构定义为:12345678910public class { int val; TreeNode left; TreeNode right; TreeN... ...
分类:
其他好文 时间:
2020-01-29 12:33:19
阅读次数:
97
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int MAXN = 110; struct Node{ int weight; v ...
分类:
其他好文 时间:
2020-01-27 23:53:49
阅读次数:
89
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int maxn = 100010; struct node{ //bool lea ...
分类:
其他好文 时间:
2020-01-27 23:31:00
阅读次数:
89
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int maxn = 100010; vector<int> child[maxn] ...
分类:
其他好文 时间:
2020-01-27 22:04:05
阅读次数:
73
法1:BFS #include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int maxn = 100010; vector<int> temp ...
分类:
其他好文 时间:
2020-01-26 22:35:05
阅读次数:
88
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int maxn = 100010; struct node{ double dat ...
分类:
其他好文 时间:
2020-01-26 22:04:59
阅读次数:
96
#include <bits/stdc++.h> #include <stdio.h> #include <stdlib.h> #include <queue> using namespace std; const int maxn = 100010; vector<int> child[maxn] ...
分类:
其他好文 时间:
2020-01-26 20:49:51
阅读次数:
111