fixing error in dublicateRandomEntry
This commit is contained in:
parent
e4a7f9ac28
commit
0a30e04157
@ -12,11 +12,24 @@
|
||||
* in `getDuplicate()`: Sortieren des Arrays und Erkennen der doppelten Zahl durch Vergleich benachbarter Elemente. */
|
||||
|
||||
static void dublicateRandomEntry (unsigned int *numbers, unsigned int len)
|
||||
{
|
||||
if (numbers && len > 2)
|
||||
{
|
||||
unsigned int dubIndx = rand() % len;
|
||||
unsigned int copyIndx = rand() % len;
|
||||
unsigned int copyIndx;
|
||||
|
||||
numbers[copyIndx] = numbers[dubIndx];
|
||||
do {
|
||||
copyIndx = rand() % len;
|
||||
} while (copyIndx == dubIndx);
|
||||
|
||||
numbers[len - 1] = numbers[dubIndx];
|
||||
|
||||
//switching last entry with random other entry
|
||||
unsigned int temp;
|
||||
temp = numbers[copyIndx];
|
||||
numbers[copyIndx] = numbers[len - 1];
|
||||
numbers[len - 1] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
static int compare(const void *a, const void *b)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user