P. 1
Swap

Swap

|Views: 0|Likes:
Published by Lê Xuân Nguyên

More info:

Published by: Lê Xuân Nguyên on Mar 11, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

03/11/2011

pdf

text

original

Tìm tất cả các hoán vị của n

phần tử.
#include <iostream>
#include <cmath>
using namespace std;
int n,a[10];
void hoanvi(int k)
{
if(k==1)
for(int j=0;j<n;j++)
cout<<a[j]<<"
";
else
for(int j=k-1;j>=0;j--)
{
swap(a[k-1],a[j]);
hoanvi(k-1);
swap(a[j],a[k-1]);
}
cout<<endl;
}
void main()
{
cout<<"Nhap n = ";
cin>>n;
for(int i=0;i<n;i++)
a[i]=i;
hoanvi(n);
}

i++) a[i]=i. cin>>n. hoanvi(n). } .i<n. for(int i=0.{ cout<<"Nhap n = ".

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->