![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
C/C++大杂烩
Champhoenix
这个作者很懒,什么都没留下…
展开
-
通过先序遍历和中序遍历重构二叉树
通过先序遍历和中序遍历重构二叉树直接上代码node* create (int preL,int preR,int inL,int inR){ if (preL>preR) return NULL; node* root=new node; root->data=pre[preL]; int k; for (k=inL;k<=inR;k++) if (pre[preL]==in[k]) break; int numLeft=k-inL; root-&原创 2021-10-25 23:52:52 · 112 阅读 · 0 评论 -
哈夫曼树思路及C++代码
哈夫曼树思路及C++代码先介绍经典的合并果子问题哈夫曼树的构建思想:反复选择最小的两个元素,合并,直至只剩下一个元素。代码:#include <stdio.h>#include <queue>using namespace std;int main (){ int n,i,x,y,a,ans=0; priority_queue<int,vector<int>,greater<int> > Q; scanf ("%d",原创 2021-10-25 13:39:25 · 2954 阅读 · 0 评论 -
BFS变形题1
BFS变形题1注:广度优先搜索,判断最小层数,要把层数放在结构体里,#include <stdio.h>#include <queue>using namespace std;struct node{ int x,y; int ans=0;}Node;const int maxn=100;char matrix[maxn][maxn];int m,n,xS,yS,xT,yT;int X[]={0,0,1,-1};int Y[]={-1,1,0,0};原创 2021-10-18 23:59:56 · 56 阅读 · 0 评论 -
BFS模板介绍
BFS模板介绍1.模板介绍2.例题(1)解:#include <stdio.h>#include <queue>using namespace std;struct node{ int x,y;}Node;const int maxn=100;int matrix[maxn][maxn];int m,n;int X[]={0,0,1,-1};int Y[]={-1,1,0,0};int inq[maxn][maxn]={0};int ju原创 2021-10-18 18:29:23 · 166 阅读 · 0 评论