commit c3942ef56eaaa00c67fc3828cc7890b32eba37fe Author: Xu Bai <1373953675@qq.com> Date: Wed Jun 26 00:36:57 2019 +0800 顺序表(未完成) diff --git a/.vscode/1.py b/.vscode/1.py new file mode 100644 index 0000000..ce47b77 --- /dev/null +++ b/.vscode/1.py @@ -0,0 +1 @@ +print("hello") \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..15a60bd --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,20 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "compilerPath": "C:\\MinGW\\bin\\gcc.exe", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "clang-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/.vscode/ipch/63c0e544b57316e2/1.ipch b/.vscode/ipch/63c0e544b57316e2/1.ipch new file mode 100644 index 0000000..b6ca5b0 Binary files /dev/null and b/.vscode/ipch/63c0e544b57316e2/1.ipch differ diff --git a/.vscode/ipch/63c0e544b57316e2/mmap_address.bin b/.vscode/ipch/63c0e544b57316e2/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/63c0e544b57316e2/mmap_address.bin differ diff --git a/.vscode/ipch/73223f58bc31aa68/mmap_address.bin b/.vscode/ipch/73223f58bc31aa68/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/73223f58bc31aa68/mmap_address.bin differ diff --git a/.vscode/ipch/e211ad9ea5ec3980/01线性表顺序存储_LIST.ipch b/.vscode/ipch/e211ad9ea5ec3980/01线性表顺序存储_LIST.ipch new file mode 100644 index 0000000..cead3e8 Binary files /dev/null and b/.vscode/ipch/e211ad9ea5ec3980/01线性表顺序存储_LIST.ipch differ diff --git a/.vscode/ipch/e211ad9ea5ec3980/mmap_address.bin b/.vscode/ipch/e211ad9ea5ec3980/mmap_address.bin new file mode 100644 index 0000000..862b842 Binary files /dev/null and b/.vscode/ipch/e211ad9ea5ec3980/mmap_address.bin differ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..d1aece3 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,23 @@ +{ + "version": "0.2.0", + "configurations": [ + + + + + { + "name": "C++ Launch (GDB)", + "type": "cppdbg", + "request": "launch", + "targetArchitecture": "x86", + "program": "${workspaceRoot}/a.out", + "miDebuggerPath":"C:\\MinGW\\bin\\gdb.exe", + "args": [], + "cwd":"${workspaceRoot}", + "stopAtEntry": false, + + "externalConsole": true, + "preLaunchTask": "g++"   + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9c473b8 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\ProgramData\\anaconda\\python.exe" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..5e500b7 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,20 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "command": "g++", + "args": ["-g","${file}","-o","a.out"], // 编译命令 + "cwd":"${workspaceRoot}", + "problemMatcher": { + "owner": "cpp", + "fileLocation": ["relative", "${workspaceRoot}"], + "pattern": { + "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", + "file": 1, + "line": 2, + "column": 3, + "severity": 4, + "message": 5 + } + } +} diff --git a/01线性表顺序存储_List.c b/01线性表顺序存储_List.c new file mode 100644 index 0000000..aecff82 --- /dev/null +++ b/01线性表顺序存储_List.c @@ -0,0 +1,233 @@ + +#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 20 /* 洢ռʼ */ + +typedef int Status; /* StatusǺ,ֵǺ״̬룬OK */ +typedef int ElemType; /* ElemType͸ʵΪint */ + +Status visit(ElemType c) +{ + printf("%d ", c); + return OK; +} + +typedef struct +{ + ElemType data[MAXSIZE]; /* 飬洢Ԫ */ + int length; /* Աǰ */ +} SqList; + +/* ʼ˳Ա */ +Status InitList(SqList *L) +{ + L->length = 0; + return OK; +} + +/* ʼ˳ԱLѴڡLΪձ򷵻TRUE򷵻FALSE */ +Status ListEmpty(SqList L) +{ + if (L.length == 0) + return TRUE; + else + return FALSE; +} + +/* ʼ˳ԱLѴڡLΪձ */ +Status ClearList(SqList *L) +{ + L->length = 0; + return OK; +} + +/* ʼ˳ԱLѴڡLԪظ */ +int ListLength(SqList L) +{ + return L.length; +} + +/* ʼ˳ԱLѴڣ1iListLength(L) */ +/* eLеiԪصֵ,עiָλã1λõǴ0ʼ */ +Status GetElem(SqList L, int i, ElemType *e) +{ + if (L.length == 0 || i < 1 || i > L.length) + return ERROR; + *e = L.data[i - 1]; + + return OK; +} + +/* ʼ˳ԱLѴ */ +/* Lе1eϵԪصλ */ +/* Ԫزڣ򷵻ֵΪ0 */ +int LocateElem(SqList L, ElemType e) +{ + int i; + if (L.length == 0) + return 0; + for (i = 0; i < L.length; i++) + { + if (L.data[i] == e) + break; + } + if (i >= L.length) + return 0; + + return i + 1; +} + +/* ʼ˳ԱLѴ,1iListLength(L) */ +/* Lеiλ֮ǰµԪeLijȼ1 */ +Status ListInsert(SqList *L, int i, ElemType e) +{ + int k; + if (L->length == MAXSIZE) /* ˳ԱѾ */ + return ERROR; + if (i < 1 || i > L->length + 1) /* iȵһλС߱һλúһλûҪʱ */ + return ERROR; + + if (i <= L->length) /* λòڱβ */ + { + for (k = L->length - 1; k >= i - 1; k--) /* Ҫλ֮Ԫƶһλ */ + L->data[k + 1] = L->data[k]; + } + L->data[i - 1] = e; /* Ԫز */ + L->length++; + + return OK; +} + +/* ʼ˳ԱLѴڣ1iListLength(L) */ +/* ɾLĵiԪأeֵLijȼ1 */ +Status ListDelete(SqList *L, int i, ElemType *e) +{ + int k; + if (L->length == 0) /* ԱΪ */ + return ERROR; + if (i < 1 || i > L->length) /* ɾλòȷ */ + return ERROR; + *e = L->data[i - 1]; + if (i < L->length) /* ɾλ */ + { + for (k = i; k < L->length; k++) /* ɾλúԪǰ */ + L->data[k - 1] = L->data[k]; + } + L->length--; + return OK; +} + +/* ʼ˳ԱLѴ */ +/* ζLÿԪ */ +Status ListTraverse(SqList L) +{ + int i; + for (i = 0; i < L.length; i++) + visit(L.data[i]); + printf("\n"); + return OK; +} + +void unionL(SqList *La, SqList Lb) +{ + int La_len, Lb_len, i; + ElemType e; + La_len = ListLength(*La); + Lb_len = ListLength(Lb); + for (i = 1; i <= Lb_len; i++) + { + GetElem(Lb, i, &e); + if (!LocateElem(*La, e)) + ListInsert(La, ++La_len, e); + } +} + +int main() +{ + + SqList L; + SqList Lb; + + ElemType e; + Status i; + int j, k; + i = InitList(&L); + printf("ʼLL.length=%d\n", L.length); + for (j = 1; j <= 5; j++) + i = ListInsert(&L, 1, j); + printf("Lıͷβ15L.data="); + ListTraverse(L); + + printf("L.length=%d \n", L.length); + i = ListEmpty(L); + printf("LǷգi=%d(1: 0:)\n", i); + + i = ClearList(&L); + printf("LL.length=%d\n", L.length); + i = ListEmpty(L); + printf("LǷգi=%d(1: 0:)\n", i); + + for (j = 1; j <= 10; j++) + ListInsert(&L, j, j); + printf("Lıββ110L.data="); + ListTraverse(L); + + printf("L.length=%d \n", L.length); + + ListInsert(&L, 1, 0); + printf("Lıͷ0L.data="); + ListTraverse(L); + printf("L.length=%d \n", L.length); + + GetElem(L, 5, &e); + printf("5ԪصֵΪ%d\n", e); + for (j = 3; j <= 4; j++) + { + k = LocateElem(L, j); + if (k) + printf("%dԪصֵΪ%d\n", k, j); + else + printf("ûֵΪ%dԪ\n", j); + } + + k = ListLength(L); /* kΪ */ + for (j = k + 1; j >= k; j--) + { + i = ListDelete(&L, j, &e); /* ɾj */ + if (i == ERROR) + printf("ɾ%dʧ\n", j); + else + printf("ɾ%dԪֵΪ%d\n", j, e); + } + printf("LԪأ"); + ListTraverse(L); + + j = 5; + ListDelete(&L, j, &e); /* ɾ5 */ + printf("ɾ%dԪֵΪ%d\n", j, e); + + printf("LԪأ"); + ListTraverse(L); + + //һ10Lb + i = InitList(&Lb); + for (j = 6; j <= 15; j++) + i = ListInsert(&Lb, 1, j); + + unionL(&L, Lb); + + printf("ϲLbLԪأ"); + ListTraverse(L); + getchar(); + return 0; +} diff --git a/_01.线性表顺序存储.c b/_01.线性表顺序存储.c new file mode 100644 index 0000000..884ed0d --- /dev/null +++ b/_01.线性表顺序存储.c @@ -0,0 +1,93 @@ +/* + * @Author: Xu Bai + * @Date: 2019-06-25 23:10:17 + * @LastEditors: Xu Bai + * @LastEditTime: 2019-06-26 00:10:55 + */ +#define MAXSIZE 20 +#define OK 1 +#define ERROR 0 +#define TRUE 1 +#define FALSE 0 + +typedef int Status; +typedef int ElemType; + +Status visit(ElemType c){ + printf("%d",c); + return OK; +} + +typedef struct +{ + ElemType data[MAXSIZE]; + int length; +}SqList; + +Status InitList(SqList *L){ + L ->length = 0; + return OK; +} + +Status ListEmpty(SqList L){ + if (L.length == 0) + { + return TRUE; + } + else + { + return FALSE; + } +} + +Status ClearList(SqList *L){ + L ->length = 0; + return OK; +} + +int ListLength(SqList L){ + return L.length; +} + +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; +} + +int LocateElem(SqList L, ElemType e){ + if (L.length == 0) + { + return ERROR; + } + int i ; + for ( i = 0; i < L.length; i++)// 长度为5,下标为0~4 + { + if (L.data[i] == e) + { + return i + 1; + } + + } + return 0; +} + +Status ListInert(SqList *L, ElemType e, int i){ + // 在第i个位置之前插入新元素e + // 初始条件:L存在且不满,且i<=length + if (L ->length == MAXSIZE || i < 1 || i > L ->length) + { + return ERROR; + } + int k; + // 插入新元素 + for (k = L ->length -1; ;) + { + /* code */ + } + + +} \ No newline at end of file diff --git a/a.out b/a.out new file mode 100644 index 0000000..478550b Binary files /dev/null and b/a.out differ