线性表

栈&队列

二叉树

持续更新中,尽请期待!!!

#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];

//算法2.13
int LocateElem_SL(SLinkList S,ElemType e){
   
    //在静态链表L中查找第1个值为e的元素
    int i = S[0].cur;//i指示表中第一个结点
    while(i&&S[i].data!=e){
    //在表中顺链查找
        i = S[i].cur;
    }
    return i;
}

//算法2.14
void InitSpace_SL(SLinkList &space){
   
    //将一维数组space中各分量链成一个备用链表,space[0].cur为头指针
    for (int i = 0; i < MAXSIZE - 1;i++){
   
        space[i].cur = i + 1;
    }
    space[MAXSIZE - 1].cur = 0;
}

//算法2.15
int Malloc_SL(SLinkList &space){
   
    //
    int i = space[0].cur;
    if(space[0].cur)
        space[0].cur = space[i].cur;
    return i;
}

//算法2.16
void Free_SL(SLinkList &space,int k){
   
    //
    space[k].cur = space[0].cur;
    space[0].cur = k;
}

//算法2.17
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;
        }
    }
}