
数据结构
wwwlps
这个作者很懒,什么都没留下…
展开
-
静态链表系列操作
静态链表#include #include using namespace std;#define maxn 105typedef struct{ int data; int cur;}stackLinkList;void init(stackLinkList *L){ for(int i=0;i<maxn-1;i++) L[i].cur=i+1;原创 2017-09-20 20:24:06 · 241 阅读 · 0 评论 -
L2-004 这是二叉搜索树吗?
https://pintia.cn/problem-sets/994805046380707840/problems/994805070971912192本题目是一道涉及二叉搜索树、树的遍历的裸题,模拟即可,可以建树,也可不建。贴个代码:#include <iostream>#include <cmath>#include <cstring>...原创 2019-03-27 10:25:32 · 133 阅读 · 0 评论 -
小根堆(模板)
#include<bits/stdc++.h>using namespace std;const int maxn=55;int n,a[maxn],heap[maxn];void siftup(int i)//建立小根堆{ int flag=0; if(i==1) return ; while(i!=1&&flag=...原创 2019-03-22 10:42:33 · 671 阅读 · 0 评论 -
trie树 (模板)
#include<bits/stdc++.h>#define LL long longusing namespace std;const int maxn=100005;const int maxz=500005;int nex[maxn];string s;int trie[maxn][26];int cnt;int endv[maxn];void build...原创 2019-03-20 11:18:38 · 96 阅读 · 0 评论 -
哈夫曼树(模板)
4198: [Noi2015]荷马史诗Time Limit:10 SecMemory Limit:512 MBSubmit:2269Solved:1216[Submit][Status][Discuss]Description追逐影子的人,自己就是影子。 ——荷马Allison 最近迷上了文学。她喜欢在一个慵懒的午后,细细地品上一杯卡布奇诺,静静地阅读她爱不释手...原创 2019-03-20 10:32:56 · 384 阅读 · 0 评论 -
堆的创建(自顶向下插入)
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#include<set>#include<queue>#include<map>#include&a原创 2018-03-04 21:30:11 · 1640 阅读 · 0 评论 -
二叉树 前序+中序->恢复二叉树后序
#include #include typedef struct k{ int data; struct k *lc,*rc;}Btree;void inputin(int in[],int n){ int i; for(i=0;i<n;i++) scanf("%d",&in[i]);}void inputpost(int pos[]原创 2017-11-21 11:30:18 · 185 阅读 · 0 评论 -
二叉树 中序+后序->还原二叉树
#include #include typedef struct k{ int data; struct k *lc,*rc;}Btree;void inputin(int in[],int n){ int i; for(i=0;i<n;i++) scanf("%d",&in[i]);}void inputpost(int post[原创 2017-11-21 11:13:18 · 205 阅读 · 0 评论 -
快速排序
#include #include #define maxn 1005using namespace std;int a[maxn];int n;void quiksort(int l,int r){ int i,j,t; i=l; j=r; if(l>r) { return ; } while(i!=j) {原创 2017-11-04 23:48:29 · 145 阅读 · 0 评论 -
队列操作
队列#include #include #define maxn 5using namespace std;typedef struct{ int data[maxn]; int head,tail;}Squeue;void init(Squeue *q){ q->head=q->tail=0;}void inSqueue(Squeue *q,int e)原创 2017-10-17 15:37:58 · 469 阅读 · 0 评论 -
单链表及系列操作
#include #include using namespace std;typedef struct Node{ int data; struct Node *next;}Node, *LinkList;void input1(LinkList *head){ LinkList p,r; int x; cin>>x;原创 2017-09-19 21:53:05 · 392 阅读 · 0 评论 -
栈stack
简单的栈typedef struct{ int data[maxn]; int top;}SqStack;void initstack(SqStack *S){ S->top=-1; return ;}void inputpush(SqStack *S){ int x; cin>>x; if(S->top==maxn-1) r原创 2017-09-25 16:34:07 · 232 阅读 · 0 评论 -
顺序表及系列操作
顺序表#include #include using namespace std;typedef struct{ int data[1005]; int length;}SqList;void input(SqList *p){ int x; cin>>x; int i=0; p->length=0; while(x!=-1)原创 2017-09-20 20:15:30 · 218 阅读 · 0 评论 -
PTA L3-002 特殊堆栈(模拟,vector,stack)
题目:https://pintia.cn/problem-sets/994805046380707840/problems/994805053695574016题解:模拟即可,保证每次插入使得数组有序,每次弹出也要使得数组有序,每次PeekMedian,直接输出数组中间值即可,但是用普通的数组模拟前两个操作会超时的,这里我们使用vector保存数据(链式结构比较好维护),并用lower_bou...原创 2019-03-29 11:10:51 · 648 阅读 · 1 评论