From 0887821949895dc78f63b1a0a0601780c4fdd1ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E5=A9=B7=E6=B9=98?= <1684173385@qq.com> Date: Mon, 30 Oct 2023 16:19:33 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 4.cpp | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 4.cpp diff --git a/4.cpp b/4.cpp new file mode 100644 index 0000000..2f9eeaf --- /dev/null +++ b/4.cpp @@ -0,0 +1,130 @@ +#include +#include +#define list_init_size 100 +#define listincrement 10 +#define ok 1 + +typedef int elemtype; +typedef int status; + +typedef struct +{ + elemtype *elem; + int length; + int listsize; +}sqlist; + + +status initlist(sqlist &l)//构造空线性表 +{ + l.elem=(elemtype * )malloc(list_init_size*sizeof(elemtype)); + l.listsize=list_init_size; + l.length=0; + return ok; +} + +status listlength(sqlist l)//得到元素的个数 +{ + return l.length; +} + +int getelem(sqlist l,int i,elemtype &e)//得到数值 +{ + if(i<1||i>l.length) + { + printf("不合法"); + return 0; + } + e=l.elem[i-1]; + return ok; +} + +status listinsert(sqlist &l,int i,elemtype e)//插入 +{ + elemtype *p,*q; + q=&(l.elem[i-1]); + for(p=&(l.elem[l.length-1]);p>=q;--p) + *(p+1)=*p; + *q=e; + ++l.length; + return ok; +} + +void listprint(sqlist l)//输出 +{ + int i; + for(i=0;i