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 | #include <stdlib.h> #include <stdio.h> void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } void printArray(int *a, int length) { printf("["); int i; for (i = 0; i < length; i++) { printf("%d",a[i]); if (i != length - 1) printf(", "); } printf("]\n"); } void permute(int *array,int i,int length) { if (length == i){ printArray(array,length); return; } int j = i; for (j = i; j < length; j++) { swap(array+i,array+j); permute(array,i+1,length); swap(array+i,array+j); } return; } int main() { int arr[] = {1,2,3}; permute(arr,0,3); return 0; } |
-
upload with new input
-
result: Success time: 0s memory: 1832 kB returned value: 0
[2, 3, 4, 5], 0, 4
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0s memory: 1832 kB returned value: 0
[2, 3, 4, 5], 0, 4
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0s memory: 1832 kB returned value: 0
3 45 7
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0s memory: 1788 kB returned value: 0
3 45 7
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0s memory: 1788 kB returned value: 0
321
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0s memory: 1788 kB returned value: 0
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.02s memory: 1676 kB returned value: 0
1,3,4,6,7
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.01s memory: 1720 kB returned value: 0
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.01s memory: 1676 kB returned value: 0
12345
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.01s memory: 1720 kB returned value: 0
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.01s memory: 1720 kB returned value: 0
1234
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.02s memory: 1676 kB returned value: 0
[2, 3, 4, 5], 0, 4
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]
-
result: Success time: 0.01s memory: 1720 kB returned value: 0
[1, 2, 3] [1, 3, 2] [2, 1, 3] [2, 3, 1] [3, 2, 1] [3, 1, 2]


