@H_
696_10@#include <stdio.h>@H_
696_10@#include <stdlib.h>@H_
696_10@#include <malloc.h>@H_
696_10@#define List_INIT_SIZE 100@H_
696_10@#define liSINCREMENT 10@H_
696_10@#define Elem
type int@H_
696_10@#define Status int@H_
696_10@typedef struct Sq
{@H_
696_10@ ElemType *elem;@H_
696_10@ int length;@H_
696_10@ int Listsize;@H_
696_10@}SqList;@H_
696_10@Status InitList(SqList *L)@H_
696_10@
{@H_
696_10@ L->elem=(ElemType*)malloc(List_INIT_SIZE*sizeof(ElemTyp
E));@H_
696_10@ if(!L->elem)@H_
696_10@ return 0;@H_
696_10@ L->length
=0;@H_
696_10@ L->Listsize=List_INIT_SIZE;@H_
696_10@ return 1;@H_
696_10@}@H_
696_10@Status Lis
Tinsert(SqList *L,int i,ElemType
E)@H_
696_10@
{@H_
696_10@ int *q,*p;@H_
696_10@ if(i<1||i>L->length)@H_
696_10@ return 0;@H_
696_10@ if(L->length>L->Listsiz
E)@H_
696_10@
{ @H_
696_10@ ElemType *newbase=(ElemType*)realloc(L->elem,(List_INIT_SIZE+liSINCREMENT)*sizeof(ElemTyp
E));@H_
696_10@ if(!newbas
E)@H_
696_10@ return 0;@H_
696_10@ L->elem=newbase;@H_
696_10@ L->Listsize+=(liSINCREMENT
);@H_
696_10@ } @H_
696_10@@H_
696_10@ q=&(L->elem[i-1]
);@H_
696_10@ for(p=&(L->elem[L->length-1]
);p>=q;--
p)@H_
696_10@ *(p+1)=*p;@H_
696_10@ *q=e;@H_
696_10@ ++L->length;@H_
696_10@ return 1;@H_
696_10@}@H_
696_10@Status List
delete(SqList *L,ElemType
E)@H_
696_10@
{@H_
696_10@ int *p,*q;@H_
696_10@ if(i<1||i>L->length)@H_
696_10@ return 0;@H_
696_10@ p=&(L->elem[i-1]
);@H_
696_10@ e=*p;@H_
696_10@ q=L->elem+L->length-1;@H_
696_10@ for(++p;p<=q;++
p)@H_
696_10@ *(p-1)=*p;@H_
696_10@ --L->length;@H_
696_10@ return 1;@H_
696_10@}@H_
696_10@int main(voID)@H_
696_10@
{@H_
696_10@ int i,j,e,lo,temp;@H_
696_10@ SqList *L=(SqList*)malloc(sizeof(SqList)
);@H_
696_10@ InitList(L
);@H_
696_10@ printf("请输顺序表的长度:\n"
);@H_
696_10@ scanf("%d",&L->length
);@H_
696_10@ printf("请输入顺序表的各个元素:\n"
);@H_
696_10@ for(i
=0;i<L->length;++i)@H_
696_10@ scanf("%d",&L->elem[i]
);@H_
696_10@ printf("输入的顺序表是:\n"
);@H_
696_10@ for (i
=0;i<L->length;++i)@H_
696_10@
{@H_
696_10@ printf("%d ",L->elem[i]
);@H_
696_10@ }@H_
696_10@ printf("\n"
);@H_
696_10@ printf("请输入插入的位置以及节点:\n"
);@H_
696_10@ scanf("%d%d",&j,&
E);@H_
696_10@ Lis
Tinsert(L,
E); @H_
696_10@ printf("插入后的顺序表为:\n"
);@H_
696_10@ for (i
=0;i<L->length;++i)@H_
696_10@
{@H_
696_10@ printf("%d ",L->elem[i]
);@H_
696_10@ }@H_
696_10@ printf("\n"
);@H_
696_10@ printf("请输入要删除的位置:"
);@H_
696_10@ scanf("%d",&lo
);@H_
696_10@ List
delete(L,tem
p);@H_
696_10@ for (i
=0;i<L->length;++i)@H_
696_10@
{@H_
696_10@ printf("%d ",L->elem[i]
);@H_
696_10@ }@H_
696_10@ printf("\n"
);@H_
696_10@ free(L
);@H_
696_10@ return 0;@H_
696_10@}@H_
696_10@