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