预览加载中,请您耐心等待几秒...
1/6
2/6
3/6
4/6
5/6
6/6

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

先引导学生学会使用顺序表和链表的程序设计,顺序表的示例使用如下: #include"stdio.h" #include"stdlib.h" #defineLIST_INIT_SIZE100 #defineLISTINCREMENT10 typedefintElemType; typedefintstatus; #defineOK1 #defineOVERFLOW-1 #defineERROR0 typedefstruct { ElemType*elem; intlength; intlistsize; }SqList; statusInitList(SqList&L) { L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType)); if(!L.elem) exit(OVERFLOW); L.length=0; L.listsize=LIST_INIT_SIZE; returnOK; } statusListInsert_Sq(SqList&L,inti,ElemTypee) { ElemType*newbase,*p,*q; if(i<1||i>L.length+1)returnERROR; if(L.length>=L.listsize) {newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTINCREMENT)*sizeof(ElemType)); if(!newbase)exit(OVERFLOW); L.elem=newbase; L.listsize=L.listsize+LISTINCREMENT; } q=&(L.elem[i-1]); for(p=&(L.elem[L.length-1]);p>=q;--p)*(p+1)=*p; *q=e; L.length++; returnOK; } statusListDelete_Sq(SqList&L,inti,ElemType&e) { ElemType*p,*q; if((i<1)||i>L.length)returnERROR; p=&L.elem[i-1]; e=*p; q=L.elem+L.length-1; for(++p;p<=q;++p) *(p-1)=*p; --L.length; returnOK; }//ListDelete_Sq main() { SqListL; inti; ElemTypee; InitList(L); for(i=0;i<5;i++) L.elem[i]=i+1; L.length=5; for(i=0;i<5;i++) printf("%d",L.elem[i]); ListInsert_Sq(L,1,0); for(i=0;i<L.length;i++) printf("%d",L.elem[i]); printf("\n"); ListDelete_Sq(L,1,e); for(i=0;i<L.length;i++) printf("%d",L.elem[i]); } 链表的示例使用如下: #include"stdio.h" #include"stdlib.h" #defineOK1 #defineERROR0 typedefintstatus; typedefintElemType; typedefstructLnode {ElemTypedata; structLnode*next; }Lnode,*Linklist; statusCreateList_L(Linklist&L,intn) { inti; Linklistp; L=(Linklist)malloc(sizeof(Lnode)); L->next=NULL; for(i=n;i>0;--i) { p=(Linklist)malloc(sizeof(Lnode)); scanf("%d",&p->data); p->next=L->next; L->next=p; } returnOK; }//createList_L statusListInsert_L(Linklist&L,inti,ElemTypee) { Linklistp,s; intj; p=L;j=0; while(p&&j<i-1){p=p->next;++j;} if(!p||j>i-1)returnERROR; s=(Linklist)malloc(sizeof(Lnode)); s->data=e; s->next=p->next;p->next=s; returnOK; }//ListInsert_L /* statusCreateList_L(Link