Last active
February 14, 2020 07:31
-
-
Save jueti/8ed9ff967fed0546bae173cd2620fc44 to your computer and use it in GitHub Desktop.
静态顺序表
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
chcp 65001 >nul 2>&1 | |
pushd %~dp0 | |
del *obj *.exe | |
popd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include "seqlist.h" | |
// 遍历 | |
void traverseList(SeqList* L) { | |
const length = GetLength(L); | |
for (int i = 0; i < length; i++) | |
printf("L[%d]=%d\n", i, L->data[i]); | |
printf(isEmpty(L) ? "Empty\n" : "\n"); | |
} | |
int main() { | |
SeqList L; | |
// 创 | |
InitList(&L); | |
// 增 | |
for (int i = 0; i < MaxSize; i++) { | |
AppendList(&L, i); | |
} | |
traverseList(&L); | |
// 删 | |
ElemType e; | |
DeleteList(&L, 5, &e); | |
printf("Deleted L[5]=%d\n", e); | |
traverseList(&L); | |
// 改 | |
SetElem(&L, 5, 88); | |
traverseList(&L); | |
// 销 | |
ClearList(&L); | |
traverseList(&L); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem del *obj *.exe | |
rem cl /c main.c stdafx.c seqlist.c | |
rem link main.obj stdafx.obj seqlist.obj | |
chcp 65001 >nul 2>&1 | |
set __VCVARSALL_TARGET_ARCH=x64 | |
set __VCVARSALL_HOST_ARCH=x64 | |
set VSCMD_ARG_no_logo=0 | |
set __PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" | |
set "__VCVARSALL_VSDEVCMD_ARGS=-arch=%__VCVARSALL_TARGET_ARCH% -host_arch=%__VCVARSALL_HOST_ARCH%" | |
call %__PATH% %__VCVARSALL_VSDEVCMD_ARGS% | |
rem cl /c main.c stdafx.c seqlist.c | |
rem link main.obj stdafx.obj seqlist.obj | |
cl /nologo /EHsc *.c | |
echo. | |
echo Complete! | |
echo. | |
rem echo wait 3s for exiting ... | |
rem choice /t 3 /d y /n >nul |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include "seqlist.h" | |
void InitList(SeqList* L) { | |
assert(L); | |
for (int i = 0; i < MaxSize; i++) { | |
L->data[i] = 0; | |
} | |
L->length = 0; | |
} | |
int GetLength(SeqList* L) | |
{ | |
assert(L); | |
return L->length; | |
} | |
bool isEmpty(SeqList* L) { | |
const _length = L->length; | |
if (_length) | |
return false; | |
return true; | |
} | |
void GetElem(SeqList* L, int i, ElemType** e) { | |
assert(i >= 1); | |
assert(i <= GetLength(L)); | |
*e = &(L->data[i - 1]); | |
} | |
void SetElem(SeqList* L, int i, const ElemType e) { | |
ElemType* s = NULL; | |
GetElem(L, i, &s); | |
if (s != NULL) | |
*s = e; | |
} | |
int LocateElem(SeqList* L, const ElemType e) { | |
const int length = GetLength(L); | |
for (int i = 0; i < length; i++) { | |
if (L->data[i] == e) | |
return i; | |
} | |
return -1; | |
} | |
bool InsertList(SeqList* L, int i, const ElemType e) { | |
const int length = GetLength(L); | |
assert(i >= 1); | |
assert(i <= length + 1); | |
assert(length <= MaxSize - 1); | |
for (int j = length; j >= i; j--) | |
if (j < MaxSize) | |
L->data[j] = L->data[j - 1]; | |
L->data[i - 1] = e; | |
L->length++; | |
return true; | |
} | |
bool AppendList(SeqList* L, const ElemType e) { | |
assert(GetLength(L) < MaxSize); | |
InsertList(L, (*L).length + 1, e); | |
return true; | |
} | |
bool DeleteList(SeqList* L, int i, ElemType* e) { | |
const int length = GetLength(L); | |
assert(i >= 1); | |
assert(i <= length); | |
*e = L->data[i - 1]; | |
for (int j = i; j < length; j++) { | |
L->data[j - 1] = L->data[j]; | |
} | |
L->data[length - 1] = 0; | |
L->length--; | |
return false; | |
} | |
void ClearList(SeqList* L) | |
{ | |
const int length = GetLength(L); | |
ElemType e; | |
for (int i = 0; i < length; i++) { | |
DeleteList(L, 1, &e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef int ElemType; | |
#define MaxSize 10 | |
typedef struct SeqList { | |
ElemType data[MaxSize]; | |
int length; | |
} SeqList; | |
void InitList(SeqList* L); | |
bool isEmpty(SeqList* L); | |
int GetLength(SeqList* L); | |
void GetElem(SeqList* L, int i, ElemType** e); | |
void SetElem(SeqList* L, int i, const ElemType e); | |
int LocateElem(SeqList* L, const ElemType e); | |
bool InsertList(SeqList* L, int i, const ElemType e); | |
bool AppendList(SeqList* L, const ElemType e); | |
bool DeleteList(SeqList* L, int i, ElemType* e); | |
void ClearList(SeqList* L); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
chcp 65001 >nul 2>&1 | |
set __VCVARSALL_TARGET_ARCH=x64 | |
set __VCVARSALL_HOST_ARCH=x64 | |
set VSCMD_ARG_no_logo=1 | |
set __PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\VsDevCmd.bat" | |
set "__VCVARSALL_VSDEVCMD_ARGS=-arch=%__VCVARSALL_TARGET_ARCH% -host_arch=%__VCVARSALL_HOST_ARCH%" | |
call %__PATH% %__VCVARSALL_VSDEVCMD_ARGS% | |
@echo on | |
@cmd /K @echo on |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <stdbool.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment