线性表
栈&队列
串
二叉树
持续更新中,尽请期待!!!
#include<bits/stdc++.h>
using namespace std;
#define Status int
#define ElemType int
#define MAXSIZE 1000
typedef struct{
ElemType data;
int cur;
} compoent, SLinkList[MAXSIZE];
int LocateElem_SL(SLinkList S,ElemType e){
int i = S[0].cur;
while(i&&S[i].data!=e){
i = S[i].cur;
}
return i;
}
void InitSpace_SL(SLinkList &space){
for (int i = 0; i < MAXSIZE - 1;i++){
space[i].cur = i + 1;
}
space[MAXSIZE - 1].cur = 0;
}
int Malloc_SL(SLinkList &space){
int i = space[0].cur;
if(space[0].cur)
space[0].cur = space[i].cur;
return i;
}
void Free_SL(SLinkList &space,int k){
space[k].cur = space[0].cur;
space[0].cur = k;
}
void difference(SLinkList &space,int &S){
InitSpace_SL(space);
S = Malloc_SL(space);
int r = S;
int m, n, data, i;
scanf("%d %d", &m, &n);
for (int j = 1; j <= m;j++){
i = Malloc_SL(space);
scanf("%d", &data);
space[i].data = data;
space[r].cur = i;
r = i;
}
space[r].cur = 0;
for (int j = 1; j <= n;j++){
int b;
scanf("%d", &b);
int p = S;
int k = space[S].cur;
while(k!=space[r].cur&&space[k].data!=b){
p = k;
k = space[k].cur;
}
if(k==space[r].cur){
i = Malloc_SL(space);
space[i].data = b;
space[i].cur = space[r].cur;
space[r].cur = i;
}else{
space[p].cur = space[k].cur;
Free_SL(space, k);
if(r==k)
r = p;
}
}
}