《数据结构》课程设计试验报告Word文件下载.docx
《《数据结构》课程设计试验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《《数据结构》课程设计试验报告Word文件下载.docx(16页珍藏版)》请在冰点文库上搜索。
界面要求简洁明了,大方得体,便于用户的使用,同时,对于用户的错误选择可以进行有效的处理。
二、问题分析
本人负责的是为用户设计菜单界面,使用户可以根据菜单进行选择其中的某个问题进行处理。
对于一个菜单界面,首先要求界面简单明了,使得用户可以轻松通过界面知道如何获取自己想要的操作。
其次,我们不能保证用户每次的选择都是有效的,即用户的选择是在我们提供的服务范围之内,所以要设计容错操作,即当用户的选择超出我们提供的范围时,提示用户重新选择。
最后,要保证用户选择相应的操作后,程序能正确的按照用户的选择运行下去,完成用户的要求。
三、数据结构描述
Intchoice;
记录用户的选择,然后选择相应的操作。
typedefstructLNode{
intnum;
intcode;
structLNode*next;
}node,*linklist;
单链表解决约瑟夫问题时储存结点信息
chara[9][9];
八皇后问题中记录棋盘信息
四、算法设计
1、程序层次模块图
程序总层次模块图
2、算法设计
voidjiemian()
{
printf("
theproblemofpeopleourofcirclr\n"
);
****************************************************\n"
*1.solvebylianbiao;
*\n"
*2.solvebyshunxubiao;
*3.help;
*4.ruturntomenu;
}
voidhelp()
*******************************************************************************\n"
*youcanchoise1,2,3or4togetthefunctionyouwant.ifyouchoise1,*\n"
*youwillsolvetheproblembylianbiao.inthisway,whenapeopleoutof*\n"
*thecircle,thenodewhichcontainhismessagewillbedeleted.ifyou*\n"
*choise2,youwillsolvetheproblembyshunxubiao.inthisway,whena*\n"
*peopleoutofthecircle,hiscodewillchangeinto0,buthismessage*\n"
*willberemained.ifyouchoise4,endthegame.*\n"
voidwelcome()
welcometooursystem\n"
*1.JosephCentralissues*\n"
*2.Queen8*\n"
*3.exit*\n"
}
intmain()
intchoice;
welcome();
pleasemakeyourchoice:
"
scanf("
%d"
&
choice);
while(choice!
=3)
{
switch(choice)
case1:
system("
cls"
Joseph();
getch();
break;
case2:
Queen();
default:
printf("
pleasechooosetherightchoice!
}
system("
五、详细程序清单
#include<
stdio.h>
conio.h>
typedefstructLNode{
//数据结构声明
inttotal;
linklistcreatstart(linklistL,intnumber)//建立单向循环链表
{
intm,i;
linklists,p;
s=L;
for(i=1;
i<
=number;
i++)
{
p=(linklist)malloc(sizeof(node));
if(!
p)exit(0);
p->
num=i;
pleaseinputthecodeofnumber%d:
i);
p->
code);
p->
next=NULL;
s->
next=p;
s=p;
next=L->
next;
returns;
voidchulie(linklistL,intnumber)//链表中的出列
intturn,i,j;
linklistp,s;
pleaseinputthestartcode:
turn);
p=L;
theturnoutofthecircleis:
=number-1;
for(j=1;
j<
=turn-1;
j++)p=p->
%d"
p->
next->
num);
turn=p->
code;
s=p->
next=s->
free(s);
\n"
voidlianbiao()//用单向循环链表解决约瑟夫问题
intnumber;
linklistL;
L=(linklist)malloc(sizeof(node));
L)exit(0);
pleaseinputthenumberofpeople:
number);
L=creatstart(L,number);
chulie(L,number);
voidjiemian()//约瑟夫问题的界面
voidshunxubiao()//用顺序表解决约瑟夫问题
inta[500]={0},i,code,number,shu;
shu=number;
printf("
a[i]);
i=0;
while(shu>
0)
while(code>
0)
{
if(i+1>
number)i=0;
if(a[i+1]!
=0)code--;
i++;
}
code=a[i];
a[i]=0;
shu--;
voidhelp()//帮助文档
voidJoseph()//约瑟夫问题
jiemian();
=4)
lianbiao();
shunxubiao();
case3:
help();
voidinit()//八皇后问题棋盘初始化
inti,j;
=8;
j++)
a[i][j]='
*'
;
voidshuchu()//输出可行解
%c"
a[i][j]);
voiddigui(inthang)//递归解决八皇后问题
intlie;
for(lie=1;
lie<
lie++)
if(panduan(hang,lie))
a[hang][lie]='
@'
if(hang!
=8)digui(hang+1);
else
{
shuchu();
total++;
}
a[hang][lie]='
intpanduan(inthang,intlie)//判断能否放置皇后
hang;
if(a[i][lie]=='
)return0;
lie;
if(a[hang][i]=='
i=hang;
j=lie;
while((i-1>
0)&
&
(j-1>
0))
if(a[i-1][j-1]=='
i--;
j--;
(j+1<
=8))
if(a[i-1][j+1]=='
i--;
j++;
return1;
voidQueen()//八皇后问题
digui
(1);
thetotalpossibilityis:
%d\n"
total);
voidwelcome()//主程序界面
intmain()//主函数
六、程序运行结果
七、使用说明
用户进入主界面后根据菜单内容选择1、2、3分别可进行约瑟夫问题、八皇后问题、退出系统操作。
进入约瑟夫问题后按照菜单选择1、2、3、4分别可进行链表求解、顺序表求解、查看帮助文档、回到主菜单操作。
进入八皇后问题系统即可输出所有的可能解,并计算解的数目。
八、心得体会
良好的界面不仅能反映出程序的主题结构,让用户了解系统的答大体功能,同时可以极大地方便用户随系统的了解与使用,增加用户与系统的交互性。