关于顺序表的插入操作程序
#include <stdio.h>#include <ctype.h>
#include <io.h>
#include <stdlib.h>
#include <process.h>
#include <malloc.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
//#define OVERFLOW -2
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 3
typedef int ElemType;
typedef int Status;
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 Destroylist(SqList *L){
free(L->elem);
L->elem=NULL;
L->length=0;
L->listsize=0;
return OK;
}
Status GetElem(SqList L,int i,ElemType *e){
if (i > L.length || i < 1)
return ERROR;
*e=*(L.elem + i - 1);
return OK;
}
Status Listinsert(SqList *L,int i,ElemType e){
ElemType *p,*q,*newbase;
if(i<1||i>L->length+1)
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;
e=*p;
++L->length;
return OK;
}
int main(void)
{
SqList L;
ElemType e;
int x,k,N,b,j,i;
Initlist(&L);
scanf("%d\n",&N);
for(i=0;i<N;i++){
scanf("%d",&b);
Listinsert(&L,i,b);
}
scanf("%d %d\n",&x,&k);
Listinsert(&L,x,k);
for(j=0;j<N+1;j++)
{
GetElem(L,j,&e);
printf ("%d ",e);
}
Destroylist(&L);
return 0;
}
来大佬帮我改改呀,谢谢了