We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 20e9877 commit 0041c93Copy full SHA for 0041c93
BackTracking/Permutation/permuta.cpp
@@ -0,0 +1,37 @@
1
+#include <stdio.h>
2
+
3
+void troca(int vetor[], int i, int j)
4
+{
5
+ int aux = vetor[i];
6
+ vetor[i] = vetor[j];
7
+ vetor[j] = aux;
8
+}
9
10
+void permuta(int vetor[], int inf, int sup)
11
12
+ if(inf == sup)
13
+ {
14
+ for(int i = 0; i <= sup; i++)
15
+ printf("%d ", vetor[i]);
16
+ printf("\n");
17
+ }
18
+ else
19
20
+ for(int i = inf; i <= sup; i++)
21
22
+ troca(vetor, inf, i);
23
+ permuta(vetor, inf + 1, sup);
24
25
26
27
28
29
+int main(int argc, char *argv[])
30
31
+ int v[] = {1, 2, 3, 4};
32
+ int tam_v = sizeof(v) / sizeof(int);
33
34
+ permuta(v, 0, tam_v - 1);
35
36
+ return 0;
37
0 commit comments