`
dato0123
  • 浏览: 914532 次
文章分类
社区版块
存档分类
最新评论

C++ Exercises(八)

 
阅读更多

全排列问题:

<!--<br /> <br /> Code highlighting produced by Actipro CodeHighlighter (freeware)<br /> http://www.CodeHighlighter.com/<br /> <br /> -->
#include
"stdafx.h"
#include
<math.h>
#include
<stdio.h>
#include
<iostream>
usingnamespacestd;

voidswap(int&a,int&b)
{
inttmp;
tmp
=a;
a
=b;
b
=tmp;
}
voidRerange(inta[],intm,intn)
{
if(m==n)
{
for(intj=0;j<=m;++j)
cout
<<a[j]<<'/t';
cout
<<endl;
}
else
{
for(inti=m;i<=n;++i)
{
swap(a[m],a[i]);

Rerange(a,m
+1,n);
swap(a[m],a[i]);

}
}
}

intmain(void)
{
inta[]={1,2,3},tmp;
Rerange(a,
0,2);
cin
>>tmp;
return0;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics