iliankostov

Permutation in C++

Oct 7th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int numbers[100000];
  4. void swapnumbers(int &a,int &b)
  5. {
  6.     int staroa = a;
  7.     a = b;
  8.     b = staroa;
  9. }
  10. void perm(int broiChisla,int stupka)
  11. {
  12.     if (stupka==broiChisla-1)
  13.     {
  14.         for (int j=0;j<broiChisla;j++)
  15.         {
  16.             cout<<numbers[j];
  17.         }
  18.         cout<<endl;
  19.     }
  20.     else
  21.     {
  22.         for (int j=stupka;j<broiChisla;j++)
  23.         {
  24.             swapnumbers(numbers[stupka],numbers[j]);
  25.             perm(broiChisla,stupka+1);
  26.             swapnumbers(numbers[stupka],numbers[j]);
  27.         }
  28.     }
  29. }
  30. int main()
  31. {
  32.     int broiChisla;
  33.     cin>>broiChisla;
  34.     for (int stupka=0; stupka<broiChisla; stupka++)
  35.     {
  36.         numbers[stupka] = stupka + 1;
  37.     }
  38.     perm(broiChisla,0);
  39.     cin>>broiChisla;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment