2025-12-05 14:43:44 +01:00

1.2 KiB

*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 -> set seed for rand() -> create new TreeNode root -> 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:

-> numbers (Zeiger != NULL) und len (min. 2) check -> define new array numbersCopy -> copy numbers to 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

compare:

-> gibt 1 aus, wenn a größer ist -> gibt -1 aus, wenn b größer ist -> gibt 0 aus wenn a==b