实验一 线性表1. 实验要求1.1 掌握数据结构中线性表的基本概念。1.2 熟练掌握线性表的基本操作:创建、插入、删除、查找、输出、求长度及合并并运算在顺序存储结构上的实验。1.3 熟练掌握链表的各种操作和应用.2. 实验内容2.1 编写一个函数,从一个给定的顺序表 A 中删除元素值在 x 到 y 之间的所有元素,要求以较高效率来实现。2.2 试写一个算法,在无头结点的动态单链表上实现线性表插入操作2.3 设计一个统计选票的算法,输出每个候选人的得票结果。3. 实验代码2.1 代码:#includedata=x;s—〉next=L;L=s;}else{p=L;j=1;while(p&&j〈i—1){j++;p=p—>next;}if(p||j>i-1)return error;s=(Linklist)malloc(sizeof(Lnode));s—>data=x;s—〉next=p-〉next;p-〉next=s;}}}2。3 代码:typedef int elemtypetypedef struct linknode{elemtype data;struct linknode *next;}nodetype;nodetype *create(){elemtype d;nodetype h=NULL,*s,*t;int i=1;printf(”建立单链表:\n");while(1){printf(”输入第%d 个结点数据域”,i);scanf(”%d",&d);if(d==0)break;if(i==1){h=(nodetype *)malloc(sizeof(nodetype));h-〉data=d;h-〉next=NULL;t=h;}else{s=(nodetype *)malloc(sizeof(nodetype));s—〉data=d;s-〉next=NULL;t—〉next=s;t=s;}i++;}return h;}void sat(nodetype *h,int a[]){nodetype *p=h;while(p!=NULL){a[p—〉data]++;p=p—〉next;}}void main(){int a[N+1],i;for(i=0;i