diff options
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/utils.c b/src/utils.c index e0d3268..354e9b0 100644 --- a/src/utils.c +++ b/src/utils.c | |||
| @@ -3,8 +3,8 @@ | |||
| 3 | void | 3 | void |
| 4 | apply_permutation(int *perm, int *set, int n) | 4 | apply_permutation(int *perm, int *set, int n) |
| 5 | { | 5 | { |
| 6 | int *aux = malloc(n * sizeof(int)); | ||
| 7 | int i; | 6 | int i; |
| 7 | int aux[n]; | ||
| 8 | 8 | ||
| 9 | if (!is_perm(perm, n)) | 9 | if (!is_perm(perm, n)) |
| 10 | return; | 10 | return; |
| @@ -13,7 +13,6 @@ apply_permutation(int *perm, int *set, int n) | |||
| 13 | aux[i] = set[perm[i]]; | 13 | aux[i] = set[perm[i]]; |
| 14 | 14 | ||
| 15 | memcpy(set, aux, n * sizeof(int)); | 15 | memcpy(set, aux, n * sizeof(int)); |
| 16 | free(aux); | ||
| 17 | } | 16 | } |
| 18 | 17 | ||
| 19 | int | 18 | int |
| @@ -53,8 +52,8 @@ factorial(int n) | |||
| 53 | void | 52 | void |
| 54 | index_to_perm(int p, int n, int *r) | 53 | index_to_perm(int p, int n, int *r) |
| 55 | { | 54 | { |
| 56 | int *a = malloc(n * sizeof(int)); | ||
| 57 | int i, j, c; | 55 | int i, j, c; |
| 56 | int a[n]; | ||
| 58 | 57 | ||
| 59 | for (i = 0; i < n; i++) | 58 | for (i = 0; i < n; i++) |
| 60 | a[i] = 0; | 59 | a[i] = 0; |
| @@ -72,8 +71,6 @@ index_to_perm(int p, int n, int *r) | |||
| 72 | a[j-1] = 1; | 71 | a[j-1] = 1; |
| 73 | p %= factorial(n-i-1); | 72 | p %= factorial(n-i-1); |
| 74 | } | 73 | } |
| 75 | |||
| 76 | free(a); | ||
| 77 | } | 74 | } |
| 78 | 75 | ||
| 79 | void | 76 | void |
| @@ -143,22 +140,22 @@ int_to_sum_zero_array(int x, int b, int n, int *a) | |||
| 143 | int | 140 | int |
| 144 | invert_digits(int a, int b, int n) | 141 | invert_digits(int a, int b, int n) |
| 145 | { | 142 | { |
| 146 | int i, ret, *r = malloc(n * sizeof(int)); | 143 | int i, ret; |
| 144 | int r[n]; | ||
| 147 | 145 | ||
| 148 | int_to_digit_array(a, b, n, r); | 146 | int_to_digit_array(a, b, n, r); |
| 149 | for (i = 0; i < n; i++) | 147 | for (i = 0; i < n; i++) |
| 150 | r[i] = (b-r[i]) % b; | 148 | r[i] = (b-r[i]) % b; |
| 151 | 149 | ||
| 152 | ret = digit_array_to_int(r, n, b); | 150 | ret = digit_array_to_int(r, n, b); |
| 153 | free(r); | ||
| 154 | return ret; | 151 | return ret; |
| 155 | } | 152 | } |
| 156 | 153 | ||
| 157 | bool | 154 | bool |
| 158 | is_perm(int *a, int n) | 155 | is_perm(int *a, int n) |
| 159 | { | 156 | { |
| 160 | int *aux = malloc(n * sizeof(int)); | ||
| 161 | int i; | 157 | int i; |
| 158 | int aux[n]; | ||
| 162 | 159 | ||
| 163 | for (i = 0; i < n; i++) | 160 | for (i = 0; i < n; i++) |
| 164 | aux[i] = 0; | 161 | aux[i] = 0; |
| @@ -174,8 +171,6 @@ is_perm(int *a, int n) | |||
| 174 | if (!aux[i]) | 171 | if (!aux[i]) |
| 175 | return false; | 172 | return false; |
| 176 | 173 | ||
| 177 | free(aux); | ||
| 178 | |||
| 179 | return true; | 174 | return true; |
| 180 | } | 175 | } |
| 181 | 176 | ||
