问题是void InitList(Sqlist *L) ,这里只是设置了len不就相当于什么都没做吗,传递结点地址怎么就初始化成结点数组,即链表了?#include <stdio.h>#include <stdlib.h>#define OK 1#define NO 0#define MAXSIZE 20typedef int bool;typedef int ElemType;int nn=0;void InitList(Sqlist *L) ///传递结点地址而已,怎么会初始链表{ L->len=0;}ElemType FindElem(Sqlist L,int n){ ElemType e; if(n>L.len) return 0; return L.data[n-1];}bool ListInsert(Sqlist *L,int n,ElemType data){ int i; if(L->len==MAXSIZE||n>L->len+1) return 0; for(i=L->len+1; i>=n; i--) { if(L->len==MAXSIZE-1) break; L->data[i]=L->data[i-1]; } L->data[n-1]=++nn; L->len++; return 1;}void main(){ Sqlist L; InitList(&L); ///这怎么就把结点初始化为链表了? int i; ElemType temp; for(i=1; i<=5; i++) { if(!ListInsert(&L,i,i)) printf("no"); } ShowList(L); }
添加回答
举报
0/150
提交
取消