#include #include #include #include #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define OK 1 #define ERROR -1 #define OVERFLOW -1 #define ENDFLAG 0 typedef int Status; typedef int ElemType; #define OUTFORMAT "%d " #define INFORMAT "%d" typedef struct{ ElemType *elem; int length; int listsize; }SqList; Status InitList(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 Inputdata(SqList *L){ ///////SqList *L 定义首节点的地址 ElemType temp,*newbase; printf("\nInput the data of the sequencial list:\nNote:0 is the ending flag:\n"); scanf(INFORMAT,&temp); while(temp!=ENDFLAG){ if(L->length>=L->listsize){ newbase=(ElemType *)realloc(L->elem, (L->listsize+LISTINCREMENT)*sizeof(ElemType));////扩 大空间,把旧的地址拷贝到新空间 if(!newbase) exit(OVERFLOW); L->elem=newbase; L->listsize+=LISTINCREMENT; } L->elem[L->length++]=temp; scanf(INFORMAT,&temp); } return OK; } Status ListInsert(SqList *L,int i,ElemType e){ ElemType *p,*q,*newbase; if(i<0||i>L->length) return ERROR; if(L->length>=L->listsize) { Newbase =( elemType*)realloc(L->elem, (L->listsize+LISTINCREMENT)*sizeof(ElemType)); if(!newbase) exit(OVERFLOW); L->elem=newbase; 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; return OK; } void MyDisplay(SqList L){ int i; for(i=0;i