diff --git a/_01.线性表/03静态链表_StaticLinkList.c b/_01.线性表/03静态链表_StaticLinkList.c new file mode 100644 index 0000000..d775f1d --- /dev/null +++ b/_01.线性表/03静态链表_StaticLinkList.c @@ -0,0 +1,158 @@ +#include "string.h" +#include "ctype.h" + +#include "stdio.h" +#include "stdlib.h" +#include "io.h" +#include "math.h" +#include "time.h" + +#define OK 1 +#define ERROR 0 +#define TRUE 1 +#define FALSE 0 + +#define MAXSIZE 1000 /* 洢ռʼ */ + +typedef int Status; /* StatusǺ,ֵǺ״̬룬OK */ +typedef char ElemType; /* ElemType͸ʵΪchar */ + + +Status visit(ElemType c) +{ + printf("%c ",c); + return OK; +} + +/* Աľ̬洢ṹ */ +typedef struct +{ + ElemType data; + int cur; /* α(Cursor) Ϊ0ʱʾָ */ +} Component,StaticLinkList[MAXSIZE]; + + +/* һάspaceиһspace[0].curΪͷָ룬"0"ʾָ */ +Status InitList(StaticLinkList space) +{ + int i; + for (i=0; i ListLength(L) + 1) + return ERROR; + j = Malloc_SSL(L); /* ÿз± */ + if (j) + { + L[j].data = e; /* ݸֵ˷data */ + for(l = 1; l <= i - 1; l++) /* ҵiԪ֮ǰλ */ + k = L[k].cur; + L[j].cur = L[k].cur; /* ѵiԪ֮ǰcurֵԪصcur */ + L[k].cur = j; /* Ԫص±긳ֵiԪ֮ǰԪصur */ + return OK; + } + return ERROR; +} + +/* ɾLеiԪ */ +Status ListDelete(StaticLinkList L, int i) +{ + int j, k; + if (i < 1 || i > ListLength(L)) + return ERROR; + k = MAXSIZE - 1; + for (j = 1; j <= i - 1; j++) + k = L[k].cur; + j = L[k].cur; + L[k].cur = L[j].cur; + Free_SSL(L, j); + return OK; +} + +Status ListTraverse(StaticLinkList L) +{ + int j=0; + int i=L[MAXSIZE-1].cur; + while(i) + { + visit(L[i].data); + i=L[i].cur; + j++; + } + return j; + printf("\n"); + return OK; +} + + +int main() +{ + StaticLinkList L; + Status i; + i=InitList(L); + printf("ʼLL.length=%d\n",ListLength(L)); + + i=ListInsert(L,1,'F'); + i=ListInsert(L,1,'E'); + i=ListInsert(L,1,'D'); + i=ListInsert(L,1,'B'); + i=ListInsert(L,1,'A'); + + printf("\nLıͷβFEDBA\nL.data="); + ListTraverse(L); + + i=ListInsert(L,3,'C'); + printf("\nLġB롰D֮롰C\nL.data="); + ListTraverse(L); + + i=ListDelete(L,1); + printf("\nLɾA\nL.data="); + ListTraverse(L); + + printf("\n"); + + return 0; +} + diff --git a/_01.线性表/_c.静态链表.c b/_01.线性表/_c.静态链表.c new file mode 100644 index 0000000..7e80b4f --- /dev/null +++ b/_01.线性表/_c.静态链表.c @@ -0,0 +1,36 @@ +#include "string.h" + +#include "stdio.h" +#include "stdlib.h" +#include "io.h" +#include "ctype.h" + +#define MAXSIZE 1000 +#define OK 1 +#define ERROR 0 +#define TRUE 1 +#define FALSE 0 + +typedef int Status; +typedef char ElemType; + +Status visit(ElemType c){ + printf("%c ",c); + return OK; +} + +typedef struct +{ + ElemType data; + int cur;// α꣬Ϊ0ʱָ +}Component,staticLinkList[MAXSIZE]; + + + + +int main() +{ + + getchar(); + return 0; +} \ No newline at end of file