#include<cstdio> #include<cstring> #include<cstdlib> #define MAXSIZE 14 #define OK 1 #define ERROR 0 #define TRUE 1 #define FALSE 0 typedef int Status; typedef int ElemType; typedef struct{ //线性表的顺序存储结构 ElemType data[MAXSIZE]; int length; }SqList; void Creat(SqList *L){ int k; L->length = 0; for(k =1;k<=5;k++){ L->data[k-1] = k; L->length++; } } Status GetElem(SqList L, int i, ElemType *e){ //获得元素操作 if (L.length == 0 || i<1||i>L.length){ return ERROR; }else{ *e = L.data[i-1]; return OK; } } Status ListInsert(SqList *L,int i,ElemType e){ //插入操作 int k; if(L->length == MAXSIZE) return ERROR; if(i<1 || i>L->length) return ERROR; if(i<=L->length){ for(k = L->length-1;k>=i-1;k--) L->data[k+1] = L->data[k]; } L->data[i-1] = e; L->length++; return OK; } Status ListDelete(SqList *L,int i,ElemType *e){ //删除操作 int k; if(L->length == 0) return ERROR; *e = L->data[i-1]; if(i<L->length){ for(k = i;k<L->length;k++) L->data[k-1] = L->data[k]; } L->length--; return OK; } void OutPut(SqList L){ int i; for(i=1;i<=L.length;i++){ printf(" %d\n",L.data[i-1]); } } int main(){ int i,w; SqList L; ElemType *e; Creat(&L); OutPut(L); while(~scanf("%d",&w)){ ListInsert(&L,w,33); OutPut(L); } //printf("ssssssssssssssssssssss %d\n",L.length); return 0; }
时间: 2024-10-05 15:21:26