欢迎来到天天文库
浏览记录
ID:56122089
大小:49.50 KB
页数:16页
时间:2020-06-20
《《数据结构》实训报告.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、实验一线性表1.实验要求1.1掌握数据结构中线性表的基本概念。1.2熟练掌握线性表的基本操作:创建、插入、删除、查找、输出、求长度及合并并运算在顺序存储结构上的实验。1.3熟练掌握链表的各种操作和应用。2.实验内容2.1编写一个函数,从一个给定的顺序表A中删除元素值在x到y之间的所有元素,要求以较高效率来实现。2.2试写一个算法,在无头结点的动态单链表上实现线性表插入操作2.3设计一个统计选票的算法,输出每个候选人的得票结果。3.实验代码2.1代码:#includetypedef
2、intelemtype;#definemaxsize10intdel(intA[],intn,elemtypex,elemtypey){inti=0,k=0;while(i=x&&A[i]<=y)k++;elseA[i-k]=A[i];i++;}return(n-k);}voidmain(){inti,j;inta[maxsize];printf("输入%d个数:",maxsize);for(i=0;i3、del(a,maxsize,1,3);printf("输出删除后剩下的数:");for(i=0;i4、));s->data=x;s->next=L;L=s;}else{p=L;j=1;while(p&&jnext;}if(p5、6、j>i-1)returnerror;s=(Linklist)malloc(sizeof(Lnode));s->data=x;s->next=p->next;p->next=s;}}}2.3代码:typedefintelemtypetypedefstructlinknode{elemtypedata;structlinknode*next;}no7、detype;nodetype*create(){elemtyped;nodetypeh=NULL,*s,*t;inti=1;printf("建立单链表:");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(8、nodetype));s->data=d;s->next=NULL;t->next=s;t=s;}i++;}returnh;}voidsat(nodetype*h,inta[]){nodetype*p=h;while(p!=NULL){a[p->data]++;p=p->next;}}voidmain(){inta[N+1],i;for(i=0;i9、;i<=N;i++)printf("%3d",i);printf("得票数");for(i=1;i<=N;i++)printf("%3d",a[i]);printf("");}1.实验小结线性表是最简单的、最常用的一种数据结构,是实现其他数据结构的基础。实验二栈与队列1.实验要求1.1了解栈和队列的特性,以便灵活运用。1.2熟练掌握栈和有关队列的各种操作和应用。2.实验内容2.1设一个算术表达式包括圆括号,方括号和花括号三种括号,编写一个算法判断其中的括号是否匹配。3.实验代码2.1代10、码:#include#include#include#defineNULL0typedefstructlist{charstr;structlist*next;}list;voidpush(char,list*);intpop(char.list*);voiddeal(char*str);main(void){charstr[20];printf("请输入一个算式:");gets(str);deal(str);pri
3、del(a,maxsize,1,3);printf("输出删除后剩下的数:");for(i=0;i4、));s->data=x;s->next=L;L=s;}else{p=L;j=1;while(p&&jnext;}if(p5、6、j>i-1)returnerror;s=(Linklist)malloc(sizeof(Lnode));s->data=x;s->next=p->next;p->next=s;}}}2.3代码:typedefintelemtypetypedefstructlinknode{elemtypedata;structlinknode*next;}no7、detype;nodetype*create(){elemtyped;nodetypeh=NULL,*s,*t;inti=1;printf("建立单链表:");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(8、nodetype));s->data=d;s->next=NULL;t->next=s;t=s;}i++;}returnh;}voidsat(nodetype*h,inta[]){nodetype*p=h;while(p!=NULL){a[p->data]++;p=p->next;}}voidmain(){inta[N+1],i;for(i=0;i9、;i<=N;i++)printf("%3d",i);printf("得票数");for(i=1;i<=N;i++)printf("%3d",a[i]);printf("");}1.实验小结线性表是最简单的、最常用的一种数据结构,是实现其他数据结构的基础。实验二栈与队列1.实验要求1.1了解栈和队列的特性,以便灵活运用。1.2熟练掌握栈和有关队列的各种操作和应用。2.实验内容2.1设一个算术表达式包括圆括号,方括号和花括号三种括号,编写一个算法判断其中的括号是否匹配。3.实验代码2.1代10、码:#include#include#include#defineNULL0typedefstructlist{charstr;structlist*next;}list;voidpush(char,list*);intpop(char.list*);voiddeal(char*str);main(void){charstr[20];printf("请输入一个算式:");gets(str);deal(str);pri
4、));s->data=x;s->next=L;L=s;}else{p=L;j=1;while(p&&jnext;}if(p
5、
6、j>i-1)returnerror;s=(Linklist)malloc(sizeof(Lnode));s->data=x;s->next=p->next;p->next=s;}}}2.3代码:typedefintelemtypetypedefstructlinknode{elemtypedata;structlinknode*next;}no
7、detype;nodetype*create(){elemtyped;nodetypeh=NULL,*s,*t;inti=1;printf("建立单链表:");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(
8、nodetype));s->data=d;s->next=NULL;t->next=s;t=s;}i++;}returnh;}voidsat(nodetype*h,inta[]){nodetype*p=h;while(p!=NULL){a[p->data]++;p=p->next;}}voidmain(){inta[N+1],i;for(i=0;i9、;i<=N;i++)printf("%3d",i);printf("得票数");for(i=1;i<=N;i++)printf("%3d",a[i]);printf("");}1.实验小结线性表是最简单的、最常用的一种数据结构,是实现其他数据结构的基础。实验二栈与队列1.实验要求1.1了解栈和队列的特性,以便灵活运用。1.2熟练掌握栈和有关队列的各种操作和应用。2.实验内容2.1设一个算术表达式包括圆括号,方括号和花括号三种括号,编写一个算法判断其中的括号是否匹配。3.实验代码2.1代10、码:#include#include#include#defineNULL0typedefstructlist{charstr;structlist*next;}list;voidpush(char,list*);intpop(char.list*);voiddeal(char*str);main(void){charstr[20];printf("请输入一个算式:");gets(str);deal(str);pri
9、;i<=N;i++)printf("%3d",i);printf("得票数");for(i=1;i<=N;i++)printf("%3d",a[i]);printf("");}1.实验小结线性表是最简单的、最常用的一种数据结构,是实现其他数据结构的基础。实验二栈与队列1.实验要求1.1了解栈和队列的特性,以便灵活运用。1.2熟练掌握栈和有关队列的各种操作和应用。2.实验内容2.1设一个算术表达式包括圆括号,方括号和花括号三种括号,编写一个算法判断其中的括号是否匹配。3.实验代码2.1代
10、码:#include#include#include#defineNULL0typedefstructlist{charstr;structlist*next;}list;voidpush(char,list*);intpop(char.list*);voiddeal(char*str);main(void){charstr[20];printf("请输入一个算式:");gets(str);deal(str);pri
此文档下载收益归作者所有