摘要: 完全二叉搜索树回溯法 #include <iostream> #include <algorithm> using namespace std; int A[100], T[100]; int n, cnt; void solve(int root) {//结点 if (root > n) return ; solve( 阅读全文
posted @ 2022-02-18 16:56 帝宝单推人! 阅读(37) 评论(0) 推荐(0)
摘要: 已知树的先序遍历和中序遍历求后序遍历 利用递归将每一个结点看成根结点 #include <iostream> using namespace std; int pre[10], in[10];//先序和中序 int post[10];//后序 void solve(int prel, int inl, int postl, int n) 阅读全文
posted @ 2022-02-17 23:22 帝宝单推人! 阅读(73) 评论(0) 推荐(0)
摘要: 邻接矩阵和邻接表笔记 邻接矩阵 #include <iostream> using namespace std; //定义边 typedef struct Enode *PtrlEnode; struct Enode { int V1, V2; //有向边<V1,V2> int weight;//权重 }; typede 阅读全文
posted @ 2022-02-17 16:57 帝宝单推人! 阅读(56) 评论(0) 推荐(0)
摘要: 并查集(数组)笔记 没有进行路径压缩 #include <iostream> #include <vector> using namespace std; typedef int Elemtype; #define Maxsize 100 typedef struct { Elemtype data; int pare 阅读全文
posted @ 2022-02-16 11:35 帝宝单推人! 阅读(33) 评论(0) 推荐(0)
摘要: 优先队列和堆 ##优先队列 特殊的“队列”,取出元素的顺序是依照元素的优先权的大小,而不是先进先出。 优先队列会进行自动排序 #include<iostream> #include<queue> using namespace std; int main() { priority_queue <int> q;// 阅读全文
posted @ 2022-02-15 23:26 帝宝单推人! 阅读(33) 评论(0) 推荐(0)
摘要: 平衡二叉树的4种旋转方法,高度以及插入代码 #include<iostream> using namespace std; struct node { int val; struct node *left; struct node *right; }; //LL旋转 node *singleLeftRotation(node *root) { 阅读全文
posted @ 2022-02-15 10:53 帝宝单推人! 阅读(157) 评论(0) 推荐(0)
摘要: 二叉搜索树的插入和删除 BinTree Insert( BinTree BST, ElementType X ) { if( !BST ){ /* 若原树为空,生成并返回一个结点的二叉搜索树 */ BST = (BinTree)malloc(sizeof(struct TNode)); BST->Data = X; BST 阅读全文
posted @ 2022-02-14 22:19 帝宝单推人! 阅读(50) 评论(0) 推荐(0)
摘要: 学生数据查询系统 #include <iostream> #include <cstring> #include <iomanip>//设置域宽头文件 using namespace std; typedef struct Link *List; typedef struct Link { string name; 阅读全文
posted @ 2022-02-11 18:15 帝宝单推人! 阅读(57) 评论(0) 推荐(0)
摘要: 试题 算法训练 数的潜能(快速幂) 正整数分解,使得乘积最大 需要把一个正整数分为多个3相加最后一个数小于等于4时停止 #include <iostream> using namespace std; typedef long long ll; ll a; ll fast_pow(ll m, ll h) {//快速幂 ll sum = 阅读全文
posted @ 2022-02-08 18:03 帝宝单推人! 阅读(319) 评论(0) 推荐(0)
摘要: 试题 算法训练 娜神平衡(二进制枚举) 二进制枚举点这里 #include <bits/stdc++.h> using namespace std; typedef long long ll; int N[10010], val1[10010], val2[10010]; int n, r, idx1, idx2; bool check( 阅读全文
posted @ 2022-02-08 17:32 帝宝单推人! 阅读(376) 评论(0) 推荐(0)