实验一线性表实验目的1、掌握线性表的逻辑结构和物理实现;2、掌握线性表的顺序存储结构和链式存储结构,熟悉对线性表的基本操作;3、在学有余力的情况下,掌握循环链表的实现及其基本操作;4、根据实验要求设计并完成程序,把理论的基本操作知识转化到实际的实践应用中
课题一的具体实验内容1、构造元素类型为整型的线性表,将以下元素插入分别插入线性表:2、查找表中是否存在元素20,实现元素20与元素9的交换;3、按照课题要求编写函数,实现线性表元素的倒置,即倒置后的表应为
主程序代码#include#include#defineNULL0structnode{intnum;structnode*next;};voidmain(){inti,flag=1;structnode*L,*s,*p,*h,*q,*k,*p1,*temp;L=(node*)malloc(sizeof(structnode));p=L;printf("请输入\n");for(i=0;inum);p->next=s;p=s;}p->next=NULL;//以上是链表的建立和输入//以下为a元素交换p=L;while(p->next->num
=20&&p->next->next
=NULL)p=p->next;if(p->next->next==NULL){printf("sorry,cannotfind
\n");flag=0;printf("原表括倒置后输出\n");}elseif(p->next->num==20){flag=1;printf("findit
\n");}if(flag==1){h=p->next;p->next=p->next->next;h->next=p->next->next;p->next->next=h;//以下为链表括的输出printf("交换后输出\n");p=L->next;whi