diff --git a/.vscode/ipch/63c0e544b57316e2/1.ipch b/.vscode/ipch/63c0e544b57316e2/1.ipch deleted file mode 100644 index b6ca5b0..0000000 Binary files a/.vscode/ipch/63c0e544b57316e2/1.ipch and /dev/null differ diff --git a/.vscode/ipch/63c0e544b57316e2/mmap_address.bin b/.vscode/ipch/63c0e544b57316e2/mmap_address.bin deleted file mode 100644 index 862b842..0000000 Binary files a/.vscode/ipch/63c0e544b57316e2/mmap_address.bin and /dev/null differ diff --git a/.vscode/ipch/73223f58bc31aa68/mmap_address.bin b/.vscode/ipch/73223f58bc31aa68/mmap_address.bin deleted file mode 100644 index 862b842..0000000 Binary files a/.vscode/ipch/73223f58bc31aa68/mmap_address.bin and /dev/null differ diff --git a/.vscode/ipch/e211ad9ea5ec3980/01线性表顺序存储_LIST.ipch b/.vscode/ipch/e211ad9ea5ec3980/01线性表顺序存储_LIST.ipch deleted file mode 100644 index cead3e8..0000000 Binary files a/.vscode/ipch/e211ad9ea5ec3980/01线性表顺序存储_LIST.ipch and /dev/null differ diff --git a/.vscode/ipch/e211ad9ea5ec3980/mmap_address.bin b/.vscode/ipch/e211ad9ea5ec3980/mmap_address.bin deleted file mode 100644 index 862b842..0000000 Binary files a/.vscode/ipch/e211ad9ea5ec3980/mmap_address.bin and /dev/null differ diff --git a/.vscode/settings.json b/.vscode/settings.json index 9c473b8..87d69fa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,6 @@ { - "python.pythonPath": "C:\\ProgramData\\anaconda\\python.exe" + "python.pythonPath": "C:\\ProgramData\\anaconda\\python.exe", + "files.associations": { + "cstdio": "c" + } } \ No newline at end of file diff --git a/_01.线性表顺序存储.c b/_01.线性表顺序存储.c index a9bdee9..52ff548 100644 --- a/_01.线性表顺序存储.c +++ b/_01.线性表顺序存储.c @@ -2,8 +2,15 @@ * @Author: Xu Bai * @Date: 2019-06-25 23:10:17 * @LastEditors: Xu Bai - * @LastEditTime: 2019-06-26 14:15:10 + * @LastEditTime: 2019-06-26 14:48:07 */ + +#include "stdio.h" + +#include "stdlib.h" +#include "io.h" +#include "math.h" +#include "time.h" #define MAXSIZE 20 #define OK 1 #define ERROR 0 @@ -13,23 +20,37 @@ typedef int Status; typedef int ElemType; -Status visit(ElemType c){ - printf("%d",c); +Status visit(ElemType c) +{ + printf("%d", c); return OK; } -typedef struct + + +typedef struct { ElemType data[MAXSIZE]; int length; -}SqList; +} SqList; -Status InitList(SqList *L){ - L ->length = 0; +Status ListTraverse(SqList L){ + int i = 0; + for ( i = 0; i <= L.length -1; i++) + { + visit(L.data[i]); + } + +} + +Status InitList(SqList *L) +{ + L->length = 0; return OK; } -Status ListEmpty(SqList L){ +Status ListEmpty(SqList L) +{ if (L.length == 0) { return TRUE; @@ -37,58 +58,85 @@ Status ListEmpty(SqList L){ else { return FALSE; - } + } } -Status ClearList(SqList *L){ - L ->length = 0; +Status ClearList(SqList *L) +{ + L->length = 0; return OK; } -int ListLength(SqList L){ +int ListLength(SqList L) +{ return L.length; } -Status GetElem(SqList L, ElemType *e, int i){ +Status GetElem(SqList L, ElemType *e, int i) +{ if (L.length == 0 || i < 1 || i > L.length) { return ERROR; } - *e = L.data[i-1]; // 返回第i个元素,下标为i -1 - return OK; + *e = L.data[i - 1]; // 返回第i个元素,下标为i -1 + return OK; } -int LocateElem(SqList L, ElemType e){ +int LocateElem(SqList L, ElemType e) +{ if (L.length == 0) { return ERROR; } - int i ; - for ( i = 0; i < L.length; i++)// 长度为5,下标为0~4 + int i; + for (i = 0; i < L.length; i++) // 长度为5,下标为0~4 { if (L.data[i] == e) { return i + 1; } - } - return 0; + return 0; } -Status ListInert(SqList *L, ElemType e, int i){ +Status ListInert(SqList *L, ElemType e, int i) +{ // 在第i个位置之前插入新元素e // 初始条件:L存在且不满,且i<=length - if (L ->length == MAXSIZE || i < 1 || i > L ->length) + if (L->length == MAXSIZE || i < 1 || i > L->length + 1) { + return ERROR; } - int k; + int k; // 插入新元素 - for (k = L ->length -1; ;) + for (k = L->length - 1; k >= i -1; k--) { - /* 测试提交 */ + L ->data[k + 1] = L ->data[k]; + // 从最后一个位置(length下标)开始移动 } + L ->data[i-1] = e; + L ->length ++; +} + + + +int main(){ + SqList L; + int isInit = InitList(&L); + if (isInit) + { + for (int j = 0; j <= 5 ; j++) + { + int res = ListInert(&L,j,1); + + } + + } + ListTraverse(L); - + getchar(); + + } \ No newline at end of file diff --git a/a.out b/a.out index 478550b..5c3c841 100644 Binary files a/a.out and b/a.out differ