欢迎来到天天文库
浏览记录
ID:12524819
大小:22.00 KB
页数:3页
时间:2018-07-17
《数据结构c语言实现顺序表的插入和删除代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#defineTRUE1#defineFALSE0#defineOK1#defineERROR0#defineINFEASIBLE-1#defineOVERFLOW-2#defineLIST_MAX_LENGTH10#defineLIST_INIT_SIZE10#defineLISTINCREMENT 2typedefstruct { int*elem; intlength; intlistsize; }SqList; SqListL; typedefintStatus; StatusInitList_Sq(SqList*L) { L->elem=(int*)malloc
2、(LIST_MAX_LENGTH*sizeof(int)); if(!L->elem)exit(OVERFLOW); L->length=0; L->listsize=LIST_INIT_SIZE; returnOK; } StatusCreateList_Sq(SqList*L,intn) { inti; L->length=n; printf("PleaseInPutNumbers:"); for(i=0;ielem[i]); printf("TheListIs:"); for(i=0;i3、 printf("%4d",L->elem[i]); printf(""); } StatusInsertList_Sq(SqList*L) { inti,m; int*p; int*q; printf("PleaseInPutTheLocation:"); scanf("%d",&i); printf("PleaseInPutTheNumberToInsert:"); scanf("%d",&m); p=&(L->elem[i-1]); for(q=L->elem+L->length-1;p<=q;--q) *(q+1)=*q; *p=m; ++L->len4、gth; printf("TheNewListIs:"); for(p=L->elem;p<=L->elem+L->length-1;p++) printf("%-4d",*p); printf(""); returnOK; } StatusListDelete_Sq(SqList*L) { inti; inte; int*p; int*q; printf("PleaseInPutTheLocationToDelete:"); scanf("%d",&i); p=&(L->elem[i-1]); e=*p; q=L->elem+L->len5、gth-1; for(++p;p<=q;++p) *(p-1)=*p; --L->length; printf("TheDeleteNumberIs%d",e); printf("TheNewListIs:"); for(p=L->elem;p<=L->elem+L->length-1;p++) printf("%-4d",*p); printf(""); returnOK; } main(){ intn,i; InitList_Sq(&L); printf("PleaseInPutLength:"); scanf("%d",&n); 6、CreateList_Sq(&L,n); InsertList_Sq(&L); ListDelete_Sq(&L); printf(""); getch();}
3、 printf("%4d",L->elem[i]); printf(""); } StatusInsertList_Sq(SqList*L) { inti,m; int*p; int*q; printf("PleaseInPutTheLocation:"); scanf("%d",&i); printf("PleaseInPutTheNumberToInsert:"); scanf("%d",&m); p=&(L->elem[i-1]); for(q=L->elem+L->length-1;p<=q;--q) *(q+1)=*q; *p=m; ++L->len
4、gth; printf("TheNewListIs:"); for(p=L->elem;p<=L->elem+L->length-1;p++) printf("%-4d",*p); printf(""); returnOK; } StatusListDelete_Sq(SqList*L) { inti; inte; int*p; int*q; printf("PleaseInPutTheLocationToDelete:"); scanf("%d",&i); p=&(L->elem[i-1]); e=*p; q=L->elem+L->len
5、gth-1; for(++p;p<=q;++p) *(p-1)=*p; --L->length; printf("TheDeleteNumberIs%d",e); printf("TheNewListIs:"); for(p=L->elem;p<=L->elem+L->length-1;p++) printf("%-4d",*p); printf(""); returnOK; } main(){ intn,i; InitList_Sq(&L); printf("PleaseInPutLength:"); scanf("%d",&n);
6、CreateList_Sq(&L,n); InsertList_Sq(&L); ListDelete_Sq(&L); printf(""); getch();}
此文档下载收益归作者所有