实验二 顺序表的操作实验报告
班 级
xxxx
学号
xxxx
姓名
xxxx
实验名称
顺序表的操作
实验目的
掌握线性表的顺序存储结构的基本概念、基本操作和应用
实验环境
硬件环境:微型计算机 软件环境: 0
#define ElemType int
#define LIST_INT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
int InitList_Sq(SqList *L){
L->elem=(ElemType *)malloc(LIST_INT_SIZE*sizeof(ElemType));
if (!L->elem) return OK;
L->length=0;
L->listsize=LIST_INT_SIZE;
return OK;}
int ListDelete_Sq(SqList *L, int i, ElemType e){
ElemType *p, *q;
if (i<1 || i>L->length) return ERROR;
p = &(L->elem[i-1]);
e = *p;
q = L->elem+L->length-1;
for (++p; p<=q; ++p) *(p-1) = *p;
if (!newbase) return ERROR;
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;}
int main(){
SqList *L;
int i,e;
if (! InitList_Sq(L)) return ERROR;
printf("Please input the length of the list(1-100) : ");
scanf("%d",& L->length);
for(i=0;i< L->length;i++)
scanf("%d",& L-> elem[i]);
printf("The old Sqlist is : \n");
for(i=0;i< L->length;i++)
printf("%d ",L-> elem[i]);
printf("\nPlease input the location to insert (1 to L->length+1) : \n");
scanf("%d",&i);
while(i<1||i> L->length+1)
{
printf("Please input the location to insert (1 to 11) : \n ");
顺序表的操作实验报告 来自淘豆网m.daumloan.com转载请标明出处.