目标:
1.栈........√
2.队列......√
3.堆.........×
4.并查集...×
栈:
1 #define MAXN 65536 2 struct stack{ 3 int sz[MAXN],now; 4 stack() 5 { 6 now=0; 7 } 8 ~stack() 9 { 10 delete []sz; 11 } 12 void push(int x) 13 { 14 if(!full()) 15 sz[++now]=x; 16 } 17 int pop() 18 { 19 if(!empty()) 20 return sz[now--]; 21 } 22 bool empty() 23 { 24 return now==0; 25 } 26 bool full() 27 { 28 return now==MAXN-1; 29 } 30 int top() 31 { 32 return sz[now]; 33 } 34 };
队列:
#define MAXN 10000 struct queue{ int sz[MAXN]; int head,tail; queue() { head=0; tail=0; } ~queue() { head=0; tail=0; delete []sz; } int front() { if(!empty()) return sz[head]; } bool empty() { return (head>=0&&tail>=0&&head==tail||head>tail); } bool full() { return tail>=MAXN; } int push(int x) { if(!full()) sz[tail++]=x; } void pop() { if(!empty()) ++head; } }
并查集:
#define maxn 10000 struct UnionFindSet { int x,y,v; int fat[maxn]; UnionFindSet() { for(int i=0;i<maxn;i++) fat[i]=i; x=y=v=0; } inline int father(int x) { if(fat[x]!=x) fat[x]=father(fat[x]); return fat[x]; } inline void unionn(int x,int y) { int fa=father(x); int fb=father(y); if(fa!=fb) fat[fa]=fb; } };