Created
September 18, 2013 09:41
-
-
Save rpplusplus/6606861 to your computer and use it in GitHub Desktop.
full_permutation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
int result_arr[100]; | |
short flag_arr[100]; | |
int result_cnt; | |
void | |
full_permutation(int arr[], int len_arr, int now_pos) | |
{ | |
int i; | |
for (i = 0; i < len_arr; ++i) | |
{ | |
if (!flag_arr[i]) | |
{ | |
flag_arr[i] = 1; | |
result_arr[now_pos] = arr[i]; | |
if (now_pos == len_arr - 1) | |
{ | |
result_cnt ++; | |
printf("No.%d\n", result_cnt); | |
int j; | |
for (j = 0; j < len_arr; ++j) | |
{ | |
printf("%d ", result_arr[j]); | |
} | |
printf("\n"); | |
} | |
else | |
{ | |
full_permutation(arr, len_arr, now_pos + 1); | |
} | |
flag_arr[i] = 0; | |
} | |
} | |
} | |
int | |
main() | |
{ | |
int arr[] = {0, 1, 2, 3, 4, 5}; | |
memset(flag_arr, sizeof(flag_arr), 0); | |
result_cnt = 0; | |
full_permutation(arr, 6, 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment