俗话说,由俭入奢易,由奢入俭难。
Python写多了,写C这种繁琐的代码,真的是难受的一批。
还是打算Python主攻,以后Java跑路,为了这瓜皮的考试学数据结构吧。(我为什么不直接学Java写??)

线性表

标头.h

#include<stdio.h>
#include<stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef int Status;
typedef int ElemType;
typedef struct {
    ElemType *elem;
    int length;
    int listsize;
}Sqlist;
Status InitList_(Sqlist *L);
Status ListInsert(Sqlist *L, int i, ElemType e);
Status ListDelete(Sqlist *L, int i, ElemType *e);
Status InitList(Sqlist *L) {
    L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
    if (!L->elem)exit(OVERFLOW);
    L->length = 0;
    L->listsize = LIST_INIT_SIZE;
    return OK;
}
Status ListInsert(Sqlist *L, int i, ElemType e) {
    ElemType *newbase, *q, *p;
    if (i < 1 || i > L->length + 1)
        return FALSE;
    if (L->length >= L->listsize) {
        newbase = (ElemType*)realloc(L->elem,
            (L->listsize + LISTINCREMENT) * sizeof(ElemType));
        if (!newbase)exit(OVERFLOW);
        L->elem = newbase;
        L->listsize += LISTINCREMENT;
    }
    q = &(L->elem[i - 1]);
    for (p = &(L->elem[L->length - 1]); p >= q; --p)*(p + 1) = *p;
    *q = e;
    ++L->length;
    return OK;
}
Status ListDelete(Sqlist *L, int i, ElemType *e) {
    ElemType *p, *q;
    if ((i < 1) || (i > L->length))
        return FALSE;
    p = &(L->elem[i - 1]);
    e = *p;
    q = L->elem + L->length - 1;
    for (++p; p <= q; ++p)*(p - 1) = *p;
    --L->length;
    return OK;
}