Advertisement
ElooEminem

Untitled

Nov 15th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h.>
  3. #include <vector.h>
  4.  
  5. using namespace std;
  6.  
  7. int *tab;
  8.  
  9. int N;
  10.  
  11. void perm(int step){
  12. int tmp;
  13. if(step==0){
  14. cout<<endl;
  15. for(int i=0;i<N;i++)
  16. cout<<tab[i]<<" ";
  17. }
  18. else{
  19. for(int i=0;i<step;i++){
  20. tmp=tab[i];
  21. tab[i]=tab[step];
  22. tab[step]=tmp;
  23.  
  24. perm(step-1);
  25.  
  26. tmp=tab[i];
  27. tab[i]=tab[step];
  28. tab[step]=tmp;
  29. }
  30. }
  31. }
  32.  
  33. void permut(int n){
  34. tab=new int [n+1];
  35. for (int i=0;i<n+1;i++)
  36. tab[i]=i;
  37. perm(n);
  38. }
  39.  
  40. int main(){
  41. N=4;
  42. permut(N);
  43. getche();
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement