修改内容:重新排版 《数据结构》试验报告 -------------线性表的插入和删除 康一飞 地理信息系统 08-2 08014208 一,实验目的 掌握线性表的顺序存储结构的定义及C语言实现插入,删除操作 掌握线性表的链式存储结构的定义及C语言实现插入,删除操作 二,实验内容 1 定义 数据元素之间的关系在计算机中又两种不同的表示方式:顺序映像和非顺序映像,由此得到两种不同的存储结构:顺序存储结构和链式存储结构
顺序映像的特点是借助元素在存储器中的相对位置来表示数据元素之间的逻辑关系 非顺序映像的特点是借助指针元素存储地址的指针表示数据元素之间的逻辑关系 2 顺序表的插入 #include #include typedef struct { int elem; int length; int listsize; }SqList,* SqL; SqL CreateList_S() { int n; SqList *p,*S; S=(SqL) malloc (sizeof(SqList)); S->listsize=100; printf("input the length of the list:"); scanf("%d",&(S->length)); printf("input the element of the list:"); for(n=1,p=S;nlength);n++,p+=sizeof(SqList)) scanf("%d",&p->elem); return(S); } SqL ListInsert_S(SqL S) { int e,i,m,n; loop: printf("input the place you want to insert:"); scanf("%d",&i); if(iS->length+1) { printf("ERROR