array
This commit is contained in:
parent
b21b3b8206
commit
f46e9b06d9
14
numbers.c
14
numbers.c
@ -24,7 +24,7 @@ CompareFctType compareFct(const void *arg1, const void *arg2)
|
|||||||
// Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries.
|
// Returns len random numbers between 1 and 2x len in random order which are all different, except for two entries.
|
||||||
// Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while
|
// Returns NULL on errors. Use your implementation of the binary search tree to check for possible duplicates while
|
||||||
// creating random numbers.
|
// creating random numbers.
|
||||||
unsigned int *createNumbers(unsigned int len)
|
unsigned int* createNumbers(unsigned int len)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
@ -55,6 +55,18 @@ unsigned int *createNumbers(unsigned int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
addToTree(numbers, duplicate->data, sizeof(int), compareFct, NULL);
|
addToTree(numbers, duplicate->data, sizeof(int), compareFct, NULL);
|
||||||
|
|
||||||
|
TreeNode* treeData = nextTreeData(numbers);
|
||||||
|
int* array = malloc(len*sizeof(int));
|
||||||
|
array[0] = treeData->data;
|
||||||
|
|
||||||
|
for (int i = 1; i < len; i++)
|
||||||
|
{
|
||||||
|
treeData = nextTreeData(NULL);
|
||||||
|
array[i] = treeData->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user