-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild_Array_from_Permutation.c
More file actions
executable file
·55 lines (44 loc) · 1.06 KB
/
Build_Array_from_Permutation.c
File metadata and controls
executable file
·55 lines (44 loc) · 1.06 KB
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
#include <stdio.h>
#include <stdlib.h>
int *buildArray(int *nums, int numsSize, int *returnSize);
void print_arr(int *nums, int numsSize);
void main()
{
int nums[] = {0, 2, 1, 5, 3, 4};
print_arr(nums, 6);
int *ret;
buildArray(nums, 6, ret);
print_arr(nums, 6);
}
// int *buildArray(int *nums, int numsSize, int *returnSize)
// {
// int *malloc_ptr = malloc(sizeof(int) * numsSize);
// for (int i = 0; i < numsSize; i++)
// {
// malloc_ptr[i] = nums[nums[i]];
// }
// returnSize = malloc_ptr;
// return returnSize;
// }
int *buildArray(int *nums, int numsSize, int *returnSize)
{
int i;
// *returnSize = numsSize;
for (i = 0; i < numsSize; i++)
{
nums[i] = (nums[nums[i] % numsSize] % numsSize) * numsSize + nums[i];
}
print_arr(nums, 6);
for (i = 0; i < numsSize; i++)
{
nums[i] = nums[i] / numsSize;
}
return nums;
}
void print_arr(int *nums, int numsSize)
{
printf("[");
for (int i = 0; i < numsSize; i++)
printf(" %i,", nums[i]);
printf("\b ]");
}