数据结构实验指导书及答案(徐州工程学院)x文档格式.docx
- 文档编号:972293
- 上传时间:2023-04-29
- 格式:DOCX
- 页数:57
- 大小:271.13KB
数据结构实验指导书及答案(徐州工程学院)x文档格式.docx
《数据结构实验指导书及答案(徐州工程学院)x文档格式.docx》由会员分享,可在线阅读,更多相关《数据结构实验指导书及答案(徐州工程学院)x文档格式.docx(57页珍藏版)》请在冰点文库上搜索。
charsubject_name[20];
doublesubject_grades;
};
structsubjectsub[10];
voidinput()
inti;
printf("
pleaseinput:
\n"
);
for(i=0;
i<
10;
i++)
scanf("
%d %s
%lf"
&
sub[i].subject_id,&
sub[i].subject_name,&
sub[i].subject_grades);
}
youjustinput:
3;
%lf\n"
sub[i].subject_id,sub[i].subject_name,sub[i].subject_grades);
voidsubject_max()
inti,flag;
doublemax=sub[0].subject_grades;
if(sub[i].subject_grades>
max)max=sub[i].subject_grades;
flag=i;
The high score of subject is %s
sub[flag].subject_name,max);
voidsubject_average()
doubleaverage,sum=sub[0].subject_grades;
for(i=1;
sum+=sub[i].subject_grades;
average=sum/10;
subject'
saverageis%lf\n"
average);
voidsubjct_gtaverage()
average)
flag=i;
subject greater than average is %s
sub[flag].subject_name,sub[flag].subject_grades);
intmain()
input();
subject_max();
subject_average();
subjct_gtaverage();
return0;
实验二顺序表的基本操作
1.熟练运用数组进行程序设计,掌握数组名和指针作为函数参数。
2.掌握结构体和结构体数组的访问与使用。
3.熟练实现顺序表类型和变量(如下所示)定于、熟悉顺序表的访问原理(顺序存储、随机访问)。
1.掌握顺序表的建立、数据元素的插入和删除、掌握数据元素的访问。
2.能够熟练的使用函数来实现顺序表的各种操作。
1.定义一顺序表类型,并定义顺序表。
2.将教材中顺序表的建立、初始化、插入、删除等函数实现。
3.顺序表能够存储10名学生的基本信息(包括姓名、学号和成绩)。
4.由主函数按照用户要求对各个顺序表操作访问。
5.每次操作之前要有明确的说明,操作后要输出操作结果。
6.分析顺序表的插入、删除、查找的时间和空间复杂度。
1.在自己的U盘的“姓名+学号”文件夹中创建“实验2”文件夹,本次实验的所有程序和数据都要求存储到本文件夹中。
2.完成顺序表操作的如下函数:
建立,初始化,增加,插入,删除。
#include"
stdio.h"
malloc.h"
#include"
string.h"
#defineLIST_INIT_SIZE1
#defineLISTINCREMENT1
structstu
{charname[6];
charnum[3];
intcj;
structsqlist
{structstu*elem;
intlength;
intlistsize;
voidmain()
{structsqlist*initlist_hc();
voidcshlist_hc(structsqlist*l);
voidlistinsert_hc(structsqlist*l);
voidlistdelete_hc(structsqlist*l);
voidlisthb_hc(structsqlist*l1,structsqlist*l2,structsqlist*l3);
structsqlist*l1,*l2,*l3;
charf;
inti,k=0;
请选择对顺序表的操作,操作菜单如下:
80;
i++)printf("
*"
建立顺序表(C)\n"
初始化顺序表(N)\n"
顺序表中插入元素(I)\n"
顺序表中删除元素(D)\n"
合并顺序表(H)\n"
退出系统(E)\n"
for(i=0;
do
{printf("
输入大写字母按Enter确定:
"
flushall();
f=getchar();
if(f=='
C'
)
{if(k==0)l1=initlist_hc();
else{l2=initlist_hc();
}k++;
elseif(f=='
N'
{if(k==1)cshlist_hc(l1);
elsecshlist_hc(l2);
}elseif(f=='
I'
{if(k==1)listinsert_hc(l1);
elselistinsert_hc(l2);
D'
{if(k==1)listdelete_hc(l1);
elselistdelete_hc(l2);
H'
{l3=initlist_hc();
listhb_hc(l1,l2,l3);
}while(f!
='
E'
}
structsqlist*initlist_hc()
{structsqlist*l;
l=(structsqlist*)malloc(sizeof(structsqlist));
if(!
l)printf("
出错!
return(l);
voidcshlist_hc(structsqlist*l)
{structstu*newbase;
voidprintlist_hc(structsqlist*l);
charx[6],y[3];
intz;
l->
elem=(structstu*)malloc(LIST_INIT_SIZE*sizeof(structstu));
if(!
l->
elem)printf("
length=0;
listsize=LIST_INIT_SIZE;
请输入信息以-1结束:
scanf("
%s%s%d"
x,y,&
z);
while(z!
=-1)
{if(l->
length==l->
listsize)
{newbase=(structstu*)realloc(l->
elem,(l->
listsize+LISTINCREMENT)*sizeof(structstu));
newbase)printf("
elem=newbase;
listsize+=LISTINCREMENT;
}strcpy(l->
elem[l->
length].name,x);
strcpy(l->
length].num,y);
l->
length].cj=z;
if(z!
=-1)l->
length++;
}printlist_hc(l);
voidlistinsert_hc(structsqlist*l)
{inti,j;
structstu*newbase;
if(l->
输入要插入信息的位置:
%d"
j);
j--;
for(i=l->
length;
i>
=j;
i--)
{strcpy(l->
elem[i+1].name,l->
elem[i].name);
strcpy(l->
elem[i+1].num,l->
elem[i].num);
elem[i+1].cj=l->
elem[i].cj;
输入插入信息:
l->
elem[j].name,l->
elem[j].num,&
elem[j].cj);
printlist_hc(l);
voidlistdelete_hc(structsqlist*l)
{voidprintlist_hc(structsqlist*l);
inti,j;
输入删除信息的位置:
删除的信息为:
%s,%s,%d\n"
elem[j].num,l->
for(i=j+1;
=l->
elem[i-1].name,l->
elem[i-1].num,l->
elem[i-1].cj=l->
}l->
length--;
voidlisthb_hc(structsqlist*l1,structsqlist*l2,structsqlist*l3)
structstu*p1,*p2,*p3;
structstu*p1_last,*p2_last;
p1=l1->
elem;
p2=l2->
l3->
length=l1->
length+l2->
length+1;
l3->
listsize=l1->
length+2;
p3=l3->
elem=(structstu*)malloc(l3->
listsize*sizeof(structstu));
p1_last=l1->
elem+l1->
p2_last=l2->
elem+l2->
while(p1<
=p1_last&
&
p2<
=p2_last)
{if(p1->
cj>
p2->
cj)
{strcpy(p3->
name,p1->
name);
strcpy(p3->
num,p1->
num);
p3->
cj=p1->
cj;
p1++;
p3++;
}else
name,p2->
num,p2->
cj=p2->
p2++;
while(p1<
=p1_last)
}while(p2<
}printlist_hc(l3);
voidprintlist_hc(structsqlist*l)
{inti;
当前表中信息如下:
elem[i].name,l->
elem[i].num,l->
elem[i].cj);
}}
实验三 单链表的基本操作
1.熟练运用指针进行程序设计,掌握结构体指针。
2.掌握使用结构体指针访问结构体变量。
3.掌握指针作为函数的参数使用。
4.理解单链表的含义、目的和处理方法。
1.掌握线性表的链式存贮结构及基本操作,深入了解链表的基本特性,以便在实际问题背景下灵活运用它们。
2.巩固该存贮结构的构造方法,深入理解和灵活掌握链表的插入、删除等操作。
操作系统:
DOS或Windows;
DOS或Windows操作系统+TurboC;
1.定义一链表类型,并定义带有头结点的单链表。
2.将教材中链表的建立、初始化、插入、删除等函数实现。
3.链表能够存储10名学生的基本信息(包括姓名、学号和成绩)。
4.由主函数按照用户要求对各个链表操作访问。
6.分析顺序表链表的插入、删除、查找的时间和空间复杂度。
1.在自己的U盘的“姓名+学号”文件夹中创建“实验3”文件夹,本次实验的所有程序和数据都要求存储到本文件夹中。
2.完成链表操作的如下函数:
//链表插入、删除、合并#include"
#include"
#defineLENsizeof(structlnode_hc)#defineLEN1sizeof(structhc_stu)
structhc_stu
{charname[3];
structlnode_hc
{structhc_stu*data;
structlnode_hc*next;
{structlnode_hc*jll();
voidcshl(structlnode_hc*head);
voidcrl(structlnode_hc*head);
voidscl(structlnode_hc*head);
voidhbl(structlnode_hc*h1,structlnode_hc*h2,structlnode_hc*h3);
structlnode_hc*h1,*h2,*h3;
请选择对链表的操作,操作菜单如下:
建立链表(C)\n"
初始化链表(N)\n"
链表中插入元素(I)\n"
链表中删除元素(D)\n"
合并链表(H)\n"
if(f=='
{if(k==0)h1=jll();
elseh2=jll();
k++;
{if(k==1)cshl(h1);
elsecshl(h2);
{if(k==1)crl(h1);
elsecrl(h2);
{if(k==1)scl(h1);
elsescl(h2);
{h3=jll();
hbl(h1,h2,h3);
structlnode_hc*jll()
{structlnode_hc*head;
head=(structlnode_hc*)malloc(LEN);
head)printf("
head->
next=NULL;
return(head);
voidcshl(structlnode_hc*head)
{voidprintl(structlnode_hc*head);
charx[3],y[3];
structlnode_hc*p1=head,*p2;
{p2=(structlnode_hc*)malloc(LEN);
p2)printf("
data=(structhc_stu*)malloc(LEN1);
data)printf("
strcpy(p2->
data->
name,x);
strcpy(p2->
num,y);
p2->
cj=z;
p1->
next=p2;
p1=p2;
}printl(head);
voidcrl(structlnode_hc*head)
intj;
structlnode_hc*p,*p1=head;
请输入要插入信息的位置:
while(j-->
1)p1=p1->
next;
p=(structlnode_hc*)malloc(LEN);
p)printf("
p->
p->
请输入要插入的信息:
p->
name,p->
num,&
cj);
p->
next=p1->
p1->
next=p;
printl(head);
voidscl(structlnode_hc*head)
structlnode_hc*p1=head,*p2=head->
请输入要删除信息的位置:
while(j>
1)
{p1=p1->
p2=p2->
j--;
p2->
next=p2->
free(p2);
voidhbl(structlnode_hc*h1,structlnode_hc*h2,structlnode_hc*h3)
{structlnode_hc*p1,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 实验 指导书 答案 徐州 工程学院