![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
Python ml
这个作者很懒,什么都没留下…
展开
-
HDU 1874(Dijkstra算法+堆优化)
#include <iostream>#include <algorithm>#include <vector>#include <string.h>#include <queue>#include <climits>using namespace std;const int MAXN=200; //顶点数const int INF=INT_MAX;struct Edge{ //边的结构原创 2022-02-28 17:37:16 · 139 阅读 · 0 评论 -
最短带权路径长度(哈夫曼树的优先队列实现)
#include <iostream>#include <queue>using namespace std;int main() { int n; while (scanf("%d",&n)!=EOF){ priority_queue<int,vector<int>,greater<int>> MypriorityQueue; //每次取出最小的两个值,小顶堆,优先级低的先输出原创 2022-02-26 20:26:29 · 382 阅读 · 0 评论 -
复数集合(优先队列、二叉堆)
#include <iostream>#include <queue>using namespace std;struct Complex{ int real,imag; Complex(int a,int b):real(a),imag(b){} //构造函数 bool operator <(Complex c) const{ //重载小于号 if(real*real+imag*imag==c.real*c.rea原创 2022-02-26 11:54:35 · 89 阅读 · 0 评论 -
简单计算器(表达式求值)
input:1+24+2*5-7/110output:3.0013.36#include <iostream>#include <cctype>#include <stack>using namespace std;int Priority(char c){ if(c=='#') return 0; else if(c=='$') return 1; else if(c=='+'||c=='-')return 2; e原创 2022-02-24 21:15:15 · 344 阅读 · 0 评论 -
括号匹配问题
#include <iostream>#include <stack>using namespace std;int main() { string s; while(cin>>s){ string ans(s.size(),' '); stack<int> brackets; for(int i=0;i<s.size();i++){ if(s[i]=='('原创 2022-02-24 20:22:54 · 233 阅读 · 0 评论 -
约瑟夫问题(队列实现)
n个小孩按1-n次序围成一圈,从编号为p的小孩开始报数,由1报到m,报到m时这名小孩从圈中出去,然后下一名小孩再从1开始报,报到m时再出去。直到所有小孩出去,输出先后出去的小孩的编号#include <iostream>#include <queue>using namespace std;int main() { int n,p,m; while (scanf("%d%d%d",&n,&p,&m)){ //n个小孩从编号p原创 2022-02-24 19:35:50 · 429 阅读 · 0 评论 -
Leetcode 707. 设计链表(Medium)
typedef struct { int val; struct MyLinkedList* next;} MyLinkedList;MyLinkedList* myLinkedListCreate() { //这个题必须用虚拟头指针,参数都是一级指针,头节点确定后没法改指向了!!! MyLinkedList*head=(MyLinkedList*)malloc(sizeof(MyLinkedList)); head->next=NULL; ret原创 2022-02-02 14:19:05 · 400 阅读 · 0 评论 -
约瑟夫问题
#include<iostream>using namespace std;int f(int n, int m){ return n == 1 ? n : (f(n - 1, m) + m - 1) % n + 1;}int main(){ int n,m; cin>>n>>m; cout<<f(n,m); system("pause"); return 0;}原创 2022-01-23 11:50:32 · 219 阅读 · 0 评论 -
PAT 1020 Tree Traversals (25 分)中序后序转(前序/层序)
#include <iostream>#include <algorithm>#include <vector>#include <map>using namespace std;vector<int> post, in;map<int, int> level;void pre(int root,int start,int end,int index){ //root子树根结点在后序中位置,start和end分别为子原创 2022-01-22 19:12:49 · 372 阅读 · 0 评论 -
PAT 1102 Invert a Binary Tree (25 分)
#include <iostream>#include <algorithm>#include <vector>using namespace std;struct node { int id, l, r, index, level;} a[100];vector<node> v1;bool cmp(node a,node b){ if(a.level!=b.level) return a.level<b.level;原创 2022-01-21 23:59:51 · 176 阅读 · 0 评论 -
PAT 1066 Root of AVL Tree (25 分)
#include <iostream>using namespace std;struct node{ int val; struct node*left,*right; };node* rotateleft(node* root){ node*t=root->right; root->right = t->left; t->left=root; return t;}node* rotateright(node*原创 2022-01-16 11:02:25 · 64 阅读 · 0 评论 -
LeetCode 中序遍历(Easy) C++
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode() : val(0), left(nullptr), right(nullptr) {} * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} *原创 2021-07-18 22:09:03 · 86 阅读 · 0 评论 -
二叉树的建立与遍历
#include <stdio.h> #include <stdlib.h>#include<stack>#include<queue>#include<iostream>using namespace std; typedef char BiElemType; typedef struct BiTNode { //二叉树结构 BiElemType c;原创 2021-05-28 17:47:16 · 82 阅读 · 0 评论 -
线索二叉树
#include <stdio.h> #include <stdlib.h>#include<stack>#include<queue>#include<iostream>#include <math.h>using namespace std;typedef char ElemType;typedef struct ThreadNode { //线索树结构 ElemType dat原创 2021-05-27 22:10:58 · 85 阅读 · 0 评论 -
Queue
//队列的相关数据结构typedef struct LinkNode{ ElemType data; struct LinkNode *next;}LinkNode;typedef struct{ LinkNode *front,*rear;}LinkQueue;void InitQueue(LinkQueue &Q){ Q.front=Q.rear=(LinkNode*)malloc(sizeof(LinkNode)); Q.front->next=NULL;}原创 2021-05-11 17:14:31 · 45 阅读 · 0 评论 -
Stack
//栈的相关数据结构#define MaxSize 50typedef BiTree ElemType;typedef struct{ ElemType data[MaxSize]; int top;}SqStack;void InitStack(SqStack &S){ S.top=-1;}bool StackEmpty(SqStack &S){ if(S.top==-1) return true; else return false;}//入栈原创 2021-05-11 17:09:45 · 48 阅读 · 0 评论