数据结构课程设计航班查询系统实验报告Word下载.docx
《数据结构课程设计航班查询系统实验报告Word下载.docx》由会员分享,可在线阅读,更多相关《数据结构课程设计航班查询系统实验报告Word下载.docx(26页珍藏版)》请在冰豆网上搜索。
本任务要求对飞机航班信息进行排序和查找。
可按航班的航班号、起点站、到达站、起飞时间以及到达时间等信息进行查询。
本设计主要是对排序以及查找等概念进行综合练习。
以链式基数排序为主线,用到二分查找和顺序查找等知识,还有建立静态链表等相关概念。
2.系统模块分析及其流程图
(1)航班排序
对输入系统内的航班首先要进行排序,我们采用的基数排序,从低位到高位依次对关键字进行分配和收集,分两段实现其算法流程图。
(2)时间查找
根据航班的起飞时间(到达时间)查找航班的信息。
(3)二分法查找功能
(4)显示功能
显示功能是将所求单词的所有行列信息依次显示在屏幕上。
四、详细设计
1.各函数说明
1.一趟分配函数
voiddistribute_c(slnode*sl,inti,arrtype_cf,arrtype_ce)
{//一趟字母分配字符函数
intj,p;
for(j=0;
j<
radix_c;
j++)
{
f[j]=e[j]=0;
}
for(p=sl[0].next;
p;
p=sl[p].next)
j=sl[p].keys[i]%65;
if(!
f[j])
f[j]=p;
else
sl[e[j]].next=p;
e[j]=p;
2.一趟收集函数
voidcollect_c(slnode*sl,inti,arrtype_cf,arrtype_ce)
intj,t;
!
f[j];
j++);
sl[0].next=f[j];
t=e[j];
while(j<
radix_c-1)
for(j=j+1;
radix_c-1&
&
if(f[j])
sl[t].next=f[j];
sl[t].next=0;
3.链式基数排序
voidradixsort(sllist&
l)//链式基数排序函数
inti;
arrtype_nfn,en;
arrtype_cfc,ec;
for(i=0;
i<
l.length;
i++)
l.sl[i].next=i+1;
l.sl[l.length].next=0;
for(i=l.keynum-1;
i>
=2;
i--)
distribute(l.sl,i,fn,en);
collect(l.sl,i,fn,en);
for(i=1;
=0;
distribute_c(l.sl,i,fc,ec);
collect_c(l.sl,i,fc,ec);
4.二分法查找函数
intbinsearch(sllistl,keytypekey[])
intlow,high,mid;
low=1;
high=l.length;
while(low<
=high)
mid=(low+high)/2;
if(strcmp(key,l.sl[mid].keys)==0)
returnmid;
elseif(strcmp(key,l.sl[mid].keys)<
0)
high=mid-1;
low=mid+1;
return0;
2.定义相关数据类型
根据设计要求我们知道所用的记录中只有航班信息,因此要定义相关的数据类型,其源程序如下:
typedefstruct
charstart[6];
//起点
charend[6];
//终点
charsche[10];
//班期
chartime1[5];
//起飞时间
chartime2[5];
//到达时间
charmodel[4];
//机型
intprice;
//票价
}infotype;
//航班记录类型
typedefstruct
keytypekeys[keylen];
//关键字,航班号
infotypeothers;
intnext;
}slnode;
//静态链表类型
slnodesl[maxspace];
//静态链表,sl[0]为头结点
intkeynum;
//记录当前关键字字符个数
intlength;
//当前表长
}sllist;
typedefintarrtype_n[radix_n];
//十进制数字指针
typedefintarrtype_c[radix_c];
//26个字母指针
3.航班信息的查询
航班信息的查询,可以根据不同的用户需求采用按航班号、起点站、终点站、起飞时间、到达时间来进行查询,其源代码如下。
voidsearchcon(sllistl)
keytypekey[keylen];
inti=1,k;
while(i>
=1&
=5)
printf("
\n********************\n"
);
*航班信息查询系统*\n"
********************\n"
*1.航班号*\n"
*2.起点站*\n"
*3.终点站*\n"
*4.起飞时间*\n"
*5.到达时间*\n"
*0.退出系统*\n"
请选择(0-5):
"
scanf("
%d"
&
i);
\n"
switch(i)
case1:
输入要查询的航班号(字母要大写):
%s"
key);
k=binsearch(l,key);
*************************************************************\n"
if(k==0)
*无此航班信息,可能是输入错误!
*\n"
*航班号起点站终点站航班期起飞时间到达时间机型票价*\n"
*%-8s%-7s%-6s%-11s%-9s%-7s%-5s%4d*\n"
l.sl[k].keys,l.sl[k].others.start,l.sl[k].others.end,l.sl[k].others.sche,l.sl[k].others.time1,l.sl[k].others.time2,l.sl[k].others.model,l.sl[k].others.price);
break;
case2:
输入要查询的航班起点站名:
seqsearch(l,key,i);
case3:
输入要查询的航班终点站名:
case4:
输入要查询的航班起飞时间:
case5:
输入要查询的航班到达时间:
case0:
\n\n\n再见\n\n\n"
5、运行由于测试
六、总结与心得
在本次试验中,遇到了很多的问题。
首先,按照书上的代码输入后,有很多错误,发现里面的代码有顺序不对的,有没有定义的等问题,经过修改解决了这些问题。
其次,就是在输入时遇到了输入不当得问题,修改输入方法后得到了修改。
最后,便是对几个算法的理解不是很透彻,对算法的具体实现了解不深。
针对以上问题,对各个算法解读了还几次,对算法的理解有了一定的理解,对整个系统运行有了全面的了解。
参考文献
[1]严蔚敏吴伟民.数据结构(C语言版).北京:
清华大学出版社.2007.
[2]谭浩强.C程序设计.北京:
清华大学出版社.1999.12.
[3]苏仕华.数据结构课程设计.机械工业出版社
附录
#include<
stdio.h>
string.h>
#definemaxspace100
#definekeylen7
#defineradix_n10
#defineradix_c26
typedefcharkeytype;
voiddistribute(slnode*sl,inti,arrtype_nf,arrtype_ne)
radix_n;
j=sl[p].keys[i]%48;
voidcollect(slnode*sl,inti,arrtype_nf,arrtype_ne)
radix_n-1)
radix_n-1&
l)//链式
voidarrange(sllist&
l)//重新整理
intp,q,i;
slnodetemp;
p=l.sl[0].next;
while(p<
i)
p=l.sl[p].next;
q=l.sl[p].next;
if(p!
=i)
temp=l.sl[p];
l.sl[p]=l.sl[i];
l.sl[i]=temp;
l.sl[i].next=p;
p=q;
voidseqsearch(sllistl,keytypekey[],inti)
intj,k,m=0;
for(j=1;
=l.length;
k=strcmp(key,l.sl[j].others.start);
k=strcmp(key,l.sl[j].others.end);
k=strcmp(key,l.sl[j].others.time1);
k=strcmp(key,l.sl[j].others.time2);
m=1;
l.sl[j].keys,l.sl[j].others.start,l.sl
[j].others.end,l.sl[j].others.sche,l.sl[j].others.time1,l.sl[j].others.time2,l.sl
[j].others.model,l.sl[j].others.price);
if(m==0)
\********************\n"
l.sl[k].keys,l.sl[k].others.start,l.sl
[k].others.end,l.sl[k].others.sche,l.sl[k].others.time1,l.sl[k].others.time2,l.sl
[k].others.model,l.sl[k].others.price);
voidinputdata(sllist&
l)
inti=++l.length;
charyn='
y'
;
while(yn=='
||yn=='
Y'
)
航班号起点站终点站航班期起飞时间到达时间机型票价\n"
%s%s%s%s%s%s%s%d"
l.sl[i].keys,l.sl[i].others.start,l.sl[i].others.end,l.sl
[i].others.sche,l.sl[i].others.time1,l.sl[i].others.time2,l.sl[i].others.model,&
l.sl
[i].others.price);
++i;
getchar();
radixsort(l);
arrange(l);
继续输入吗?
y/n:
%c"
yn);
l.length=i-1;
voidmain()
sllistl;
l.keynum=6;
l.length=0;
inputdata(l);
searchcon(l);