|
发表于 2021-4-13 09:25:53
|
显示全部楼层
- #include<stdio.h>
- #include<stdlib.h>
- #define OK 1
- #define ERROR 0
- #define OVERFLOW -2
- typedef int ElemType;
- typedef int Status;
- const LIST_INIT_SIZE=100;
- const LISTINCREMENT=100;
- typedef struct
- {
- ElemType *elem;
- int length;
- int listsize;
- }SqList;
- Status ListInit(SqList *L)//构造一个空的线性表
- {
- L->elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
- if(!L->elem)
- {
- exit(OVERFLOW);
- }
- L->length=0;
- L->listsize=LIST_INIT_SIZE;
-
- return OK;
- }
- Status GetElem1(SqList L)//得到L中位置i上的元素e并返回 ---> 你返回啥了? 啥也没返回啊...
- {
- int i;
- ElemType *e;
- for(i=0;i<L.length;i++)
- {
- if(i%2==0)
- {
- *e=L.elem[i];
- }
- }
- }
- Status GetElem2(SqList L)//得到L中位置i上的元素e并返回 ---> 和上面一样,啥也没返回
- {
- int i;
- ElemType *e;
- for(i=0;i<L.length;i++)
- {
- if(i%2!=0)
- {
- *e=L.elem[i];
- }
- }
- }
- int main()
- {
- int i;
- SqList *Lb,*Lc;
- SqList La={1,2,3,4,5,6,7};
- ListInit(Lb);
- ListInit(Lc);
- Lb=GetElem1(La); // ---> 这里 GetElem1 和 GetElem2返回值都是int Lb和Lc是什么类型?
- Lc=GetElem2(La);
-
- for(i=0;i<7;i++)
- printf("%d",Lb->elem[i]);
- printf("%d",Lc->elem[i]);
-
- return OK;
-
- return OK;
- }
复制代码 |
|