![](https://img-blog.csdnimg.cn/20210814220928238.jpg?x-oss-process=image/resize,m_fixed,h_224,w_224)
数据结构
热爱计算机
厦门摩块诗信息科技
微信号:xmwqhh,提供软件开发服务
展开
-
哈夫曼树构造,编码,译码
code is beautiful运行结果:使用频率小的编码尽量短详解:1.构造(链表实现)要点:一.采用STL优先队列筛选出权值小的两个节点,重写比较方式struct cmp { //重写仿函数 bool operator()(Node* a, Node* b) { return a->weight > b->weight;//小顶堆...原创 2021-11-28 09:53:20 · 507 阅读 · 0 评论 -
C++表达式求值
"sharinghappiness is happy" -2021-10-8一.细节处理:1.注意负数 因此要进行字符串预处理string format(string str) { int len = str.length(); fo...原创 2021-10-08 20:56:19 · 916 阅读 · 0 评论 -
完全二叉树应用
完全二叉树:假如该树的总层数为k层,则k-1层为满二叉树,第k层叶子节点尽量位于左子树题目:http://xujcoj.com/home/problem/detail/2921题解:1.利用队列优先插入左节点2.然后采取层次遍历,去访问每个节点3.该写法要注意root根节点和左右节点都要在构造函数中进行初始化AC代码:#include<iostream>#include<cstring>#include<queue>using nam.原创 2021-09-07 05:04:56 · 420 阅读 · 0 评论 -
floyd进阶,最大频率栈,反向链表,kthsmallest
1.反向输出链表(利用栈的特性)p2 = p1->next;p3 = p2->next; //p2会产生空指针 因为p1->next是空 不能赋值给p2否则会报错应该写成:p1->next=p2;p2->next=p3;#define _CRT_SECURE_NO_WARNINGS#include<bits/stdc++.h>using namespace std;//反向输出链表 采用栈的特点struct ListNode{ i原创 2021-09-05 06:06:34 · 150 阅读 · 0 评论 -
双链表实现
1.相比于单链表多一个可以访问后面节点的前驱节点插入操作:newNode->_next = pos;pos->_front->_next = newNode;newNode->_front = pos->_front;pos->_front = newNode;删除操作:Node<T>* front = pos->_front;Node<T>* next = pos->_next;next->_fro原创 2021-08-30 08:59:12 · 99 阅读 · 0 评论 -
平衡二叉搜索树
定义:1.一棵二叉搜索树,满足右节点大于(或等于父节点),左节点小于(或等于)父节点2.同时又满足每个节点的左子树的高度减去右子树的高度不大于1,即为-1 0 1.涉及知识点:1.插入分为以下几种情况:LL型 RR型 LR型 RL型2....原创 2021-08-28 16:23:06 · 103 阅读 · 0 评论 -
栈的两种实现方式
动态数组实现:#define CURL_STATICLIB# include<iostream># include<string>#include<assert.h>using namespace std;template<typename T>class Mystack{private: T* arr; int _count; int cap;//容量 int length;public: My原创 2021-08-27 15:19:35 · 81 阅读 · 0 评论 -
最大流问题
1.网络流:在一个有向图中u,v代表顶点 G(u,v)代表从u到v上的流量S代表源点,T代表汇点最大流:1.源点到汇点路径上的最大流量2.如何求:1.利用dfs()去搜源点到汇点的最大流,但这个最大流必须是这条路径上的最小流量.然后正向边减去相应的最小流量,反向边加上相应的最小流量,这就是建立增广路径2.然后利用bfs()去判断是否能存在源点到汇点的增广路,不存在结束,求出最大流模板题目:http://poj.org/problem?id=1273AC代码:原创 2021-08-27 07:53:50 · 88 阅读 · 0 评论 -
队列实现原理和应用
循环数组实现队列:#define _CRT_SECURE_NO_WARNINGS#include<bits/stdc++.h>using namespace std;template<class T>class LoopQueue{public: LoopQueue(int c ); ~LoopQueue();public: bool isEmpty(); int size(); bool push(T t); bool pop(); T front原创 2021-08-26 07:42:21 · 131 阅读 · 0 评论 -
二叉搜索树模板
二叉树:每个节点最多只有两个节点二叉搜索树:性质:左子树不为空,左节点上的值都必须小于根节点上的值,若右子树不为空,右节点上的值必须大于根节点上的值体现在insert这个步骤上template <typename T>void BSTree<T>::insert(T key){ BSNode<T>* pparent = nullptr; BSNode<T>* pnode = root; while (pnode != nullptr原创 2021-08-20 15:16:14 · 208 阅读 · 1 评论 -
基于kruskal的最小生成树
生成树:一个联通图中还有n个顶点但却只有n-1个顶点最小生成树:权值最小的生成树kruskal算法:并查集思想1.n个顶点 连接n-1个边2.采用快排选出最小的边模板代码:#define _CRT_SECURE_NO_WARNINGS#include<iostream>using namespace std;const int maxn = 2e5 + 10;int u, v;long long sum;int f[maxn];int ans;struct原创 2021-08-18 15:25:22 · 61 阅读 · 0 评论 -
建图 bfs and dfs
题目:https://www.luogu.com.cn/problem/P5318题解:#include<bits/stdc++.h>using namespace std;const int N = 1e5 + 5;typedef long long ll;vector<int>e[N];int v[N];int n, m;void add(int a, int b){ e[a].emplace_back(b);}//两种实现方式void dfs(原创 2021-08-14 22:11:22 · 64 阅读 · 0 评论