small fix

This commit is contained in:
Jonas Urban 2025-11-25 22:01:56 +01:00
parent 0a30e04157
commit 2f3fee4cb2
2 changed files with 8 additions and 7 deletions

View File

@ -1,4 +1,4 @@
*createNumbers:
*createNumbers: -> numbers array gets filled with random entry with only one dublicate
-> check if len is greater than 2
-> create new array numbers, use malloc and check if correct
@ -7,7 +7,10 @@
-> add new value to tree using addToTree and rand()
-> addToTree sets isDup to 1, if value already exists
-> if value does not already exist -> add to numbers[]
->
-> stops at numbers[len -2]
static dublicateRandomEntry:
-> numbers[len-1] is filled with random already existing number
-> numbers[len -1] gets switched with other random entry -> dublicate is placed randwom in entry; without the switch, dublicate would always be at the end
getDublicate:
@ -15,7 +18,7 @@ getDublicate:
-> numbers (Zeiger != NULL) und len (min. 2) check
-> define new array numbersCopy
-> copy numbers to numbersCopy
-> simple loop to copy each element number -> numbersCopy
-> simple loop to copy each element from numbers to numbersCopy
-> sort numbersCopy with qsort
-> compare each element of numbersCopy with next element (if numbersCopy[i] == numbersCopy[i+1] -> dublicate was found, because same values are right next to each other)
-> return found dublicate

View File

@ -15,12 +15,10 @@ static void dublicateRandomEntry (unsigned int *numbers, unsigned int len)
{
if (numbers && len > 2)
{
unsigned int dubIndx = rand() % len;
unsigned int dubIndx = rand() % (len - 1);
unsigned int copyIndx;
do {
copyIndx = rand() % len;
} while (copyIndx == dubIndx);
copyIndx = rand() % len;
numbers[len - 1] = numbers[dubIndx];