fork download
  1. #include <iostream>
  2. using namespace std;
  3. #define swap(x,y,t) ((t)=(x), (x)=(y), (y)=(t))
  4. void perm(char *list, int i, int n);
  5.  
  6. int main(){
  7. char a[4]={'a','b','c'};
  8. perm(a,0,2);
  9. //cout<<a<<endl;
  10.  
  11.  
  12. return 0;
  13. }
  14.  
  15. void perm(char *list, int i, int n){
  16. int j, temp;
  17. if (i==n){
  18. for (j=0; j<=n; j++)
  19. printf("%c", list[j]);
  20. printf(" ");
  21. }
  22. else {
  23. for (j=i; j<=n; j++){
  24. swap(list[i],list[j],temp);
  25. perm(list,i+1,n);
  26. swap(list[i],list[j],temp);
  27. //cout<<list<<endl;
  28. }
  29. }
  30. }
  31.  
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
abc     acb     bac     bca     cba     cab