Hoán Vị Liệt Kê

#include <stdio.h> #include <conio.h> #define MAX 8 #include<iostream> using namespace std; void Hoandoi(int &A,int &B); int main() { int x[MAX],a,b,n,i,k,dem=1; //===========Nhap do { cout<<"in put n but not limit "<<MAX<<"phan tu"; scanf("%d",&n); }while(n<1||n>MAX); //===========Xuat for( i=0;i<n;i++) x[i]=i+1; while(i>=0) { printf("%2d. ",dem++); for(i=0;i<n;i++) printf("%d",x[i]); printf("\n"); i=n-2; while(i>=0&&x[i]>x[i+1]) i--; if(i>=0) { k=n-1; while(x[k]<x[i]) k--; Hoandoi(x[k],x[i]); a=i+1; b=n-1; while(a<b) Hoandoi(x[a++],x[b--]); } } getch(); } void Hoandoi(int &A,int &B) { int temp=A; A=B; B=temp; }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.