-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathPermutations.cpp
More file actions
57 lines (52 loc) · 956 Bytes
/
Copy pathPermutations.cpp
File metadata and controls
57 lines (52 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Petar 'PetarV' Velickovic
Algorithm: Permutations
*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long lld;
int n;
int niz[100];
bool inPerm[100];
int currPerm[100];
//Algoritam koji generise sve permutacije datog niza
//Slozenost: O(n!)
void generatePermutations(int pos)
{
if (pos == n)
{
for (int i=0;i<n;i++) printf("%d ",currPerm[i]);
printf("\n");
}
for (int i=0;i<n;i++)
{
if (!inPerm[i])
{
currPerm[pos] = niz[i];
inPerm[i] = true;
generatePermutations(pos+1);
inPerm[i] = false;
}
}
}
int main()
{
n = 3;
niz[0] = 1;
niz[1] = 2;
niz[2] = 3;
generatePermutations(0);
return 0;
}