修改内容:重新排版 《数据结构》试验报告 -------------线性表的插入和删除 康一飞 地理信息系统 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;n<=(S->length);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(i<1||i>S->length+1) { printf("ERROR input again\n"); goto loop; } printf("iuput the element you want to insert:"); scanf("%d",&e); m=S->length; for(n=i;n<=S->length;n++) { (S+m*sizeof(SqList))->elem=(S+(m-1)*sizeof(SqList))->elem; m=m-1; } (S+(i-1)*sizeof(SqList))->elem=e; S->length++; return(S); } void main() { SqList *Sa,*p; int n,i,e; Sa=CreateList_S(); printf("the list is:"); for(n=1,p=Sa;n<=(Sa->length);n++,p+=sizeof(SqList))printf("%d ",p->elem); printf("\n\n"); Sa= ListInsert_S(Sa); printf("the list is:"); for(n=1,p=Sa;n<=(Sa->length);n++,p+=sizeof(SqList))printf("%d ",p->elem); printf("\n"); } 3 单链表的删除 #include #include #define NULL 0 typedef struct LNode { int data; struct LNode *next; }LNode,*LiL; LiL CreatList_L() { int i,n; LNode *p,*L; L=(LiL)malloc(sizeof(LNod...