欢迎来到天天文库
浏览记录
ID:44149783
大小:146.71 KB
页数:3页
时间:2019-10-19
《山东大学数据结构实验报告一》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、数据结构实验报告一一实验一实验题目:递归练习学号:201411130001日期:2015.11.26班级:计机14.1姓名:刘方铮Email:liul91150932@163.com实验目的:熟悉开发工具的使用。掌握递归的实现思想。任务要求:输出n个整数的全排列。输岀n个整数的所有子集软件环境:Win7操作系统开发工具:visualC++6.0实验代码:#includeusingnamespacestd;voidoutput(chard[],intn)〃输出{for(inti二0;ivn;i++)cout«d[i];cout«M}voidswap(c
2、har&x,char&y)〃交换{chart=x;x二y;y=t;}voidperm(chard[],intn,intj)//j起始下标{if(j==n)output(d,n);//输出elsefor(inti=j;i3、n";cin»n;perm(a5n50);cout«endl;system(npauseH);return0;}#includeconstintMAXN=10;//n的最大值constintLEN=MAXN;//用來打印子集voidprintAns(intnum[],intlen){printf(u{H);for(inti=0;i4、i]);}printf(n}H);}//递归voidfun(intx,intnum[],intlen){printAns(num,l5、en);for(inti=x・1;i>=1;—i){num[len++]=i;fun(i,num,len);len—;}}intmain(){intnumber;intansfLEN];scanf(n%dn,&number);for(inti=l;iv=number;++i){ans6、0]=i;fun(i,ans,1);}printAns(ans,0);〃空集return0;}实验结果:•••□abcdeubcedabdceubdecabedcubecdaebdeuebeduedbeuedebucedbacebdudebeadeebudbeeudbecudebcudee7、buecdbaecbduvdcbuvdbcu«bdcuebedbacdebuevdbudeebad«cbaedcbuecdbcudebcaedbedaebedeubcedubewudbdcuvbdeeabduevbduvebdeacbdecabeedabecadbedcabedacbeadcbeacdcbadecbaedcbdaecbdeacbedacbeadcabdecabedcadbecadebcaedbcaebdcdabecdaebedbaoedbeacdebacdeabceadbceabdcedabcedbacebdacebaddbcaedbceadbacedb8、aecdbeacdbecadebaedebeadcah<»dc*ohdconbdeebad^cbpdacphdnbcod*b@cdaobcda^cbd^cabdpebadpacbd的bedphne“be*obc"pbcad^hdeaobdMebadcebacdeebdaecbadecdbaecdabecadbecabd色debaedcabedbeaedbaeedabeedacbeacdbeacbdeadebeadbceabdc“bedocessreturned0(0x0)executiontime:3.953sessanykeytocontinue・
3、n";cin»n;perm(a5n50);cout«endl;system(npauseH);return0;}#includeconstintMAXN=10;//n的最大值constintLEN=MAXN;//用來打印子集voidprintAns(intnum[],intlen){printf(u{H);for(inti=0;i4、i]);}printf(n}H);}//递归voidfun(intx,intnum[],intlen){printAns(num,l5、en);for(inti=x・1;i>=1;—i){num[len++]=i;fun(i,num,len);len—;}}intmain(){intnumber;intansfLEN];scanf(n%dn,&number);for(inti=l;iv=number;++i){ans6、0]=i;fun(i,ans,1);}printAns(ans,0);〃空集return0;}实验结果:•••□abcdeubcedabdceubdecabedcubecdaebdeuebeduedbeuedebucedbacebdudebeadeebudbeeudbecudebcudee7、buecdbaecbduvdcbuvdbcu«bdcuebedbacdebuevdbudeebad«cbaedcbuecdbcudebcaedbedaebedeubcedubewudbdcuvbdeeabduevbduvebdeacbdecabeedabecadbedcabedacbeadcbeacdcbadecbaedcbdaecbdeacbedacbeadcabdecabedcadbecadebcaedbcaebdcdabecdaebedbaoedbeacdebacdeabceadbceabdcedabcedbacebdacebaddbcaedbceadbacedb8、aecdbeacdbecadebaedebeadcah<»dc*ohdconbdeebad^cbpdacphdnbcod*b@cdaobcda^cbd^cabdpebadpacbd的bedphne“be*obc"pbcad^hdeaobdMebadcebacdeebdaecbadecdbaecdabecadbecabd色debaedcabedbeaedbaeedabeedacbeacdbeacbdeadebeadbceabdc“bedocessreturned0(0x0)executiontime:3.953sessanykeytocontinue・
4、i]);}printf(n}H);}//递归voidfun(intx,intnum[],intlen){printAns(num,l
5、en);for(inti=x・1;i>=1;—i){num[len++]=i;fun(i,num,len);len—;}}intmain(){intnumber;intansfLEN];scanf(n%dn,&number);for(inti=l;iv=number;++i){ans
6、0]=i;fun(i,ans,1);}printAns(ans,0);〃空集return0;}实验结果:•••□abcdeubcedabdceubdecabedcubecdaebdeuebeduedbeuedebucedbacebdudebeadeebudbeeudbecudebcudee
7、buecdbaecbduvdcbuvdbcu«bdcuebedbacdebuevdbudeebad«cbaedcbuecdbcudebcaedbedaebedeubcedubewudbdcuvbdeeabduevbduvebdeacbdecabeedabecadbedcabedacbeadcbeacdcbadecbaedcbdaecbdeacbedacbeadcabdecabedcadbecadebcaedbcaebdcdabecdaebedbaoedbeacdebacdeabceadbceabdcedabcedbacebdacebaddbcaedbceadbacedb
8、aecdbeacdbecadebaedebeadcah<»dc*ohdconbdeebad^cbpdacphdnbcod*b@cdaobcda^cbd^cabdpebadpacbd的bedphne“be*obc"pbcad^hdeaobdMebadcebacdeebdaecbadecdbaecdabecadbecabd色debaedcabedbeaedbaeedabeedacbeacdbeacbdeadebeadbceabdc“bedocessreturned0(0x0)executiontime:3.953sessanykeytocontinue・
此文档下载收益归作者所有