VanDavv / IT-Labs

Solved tasks from IT labs on ZUT
2 stars 0 forks source link

unique int for every struct #2

Closed Tommac1 closed 6 years ago

Tommac1 commented 7 years ago

Requirement was, that for every int field, it's value must be unique .

Consider adding the following code to make it done

do { structs[i]->i = (rand() % 10001) - 1000; present = 0; for (j = 0; (j < i) && (present == 0); ++j) { if (structs[j]->i == structs[i]->i) { present = 1; } } } while (present == 1);

EDIT Please describe issue mode in detail when submitting ~VanDavv

VanDavv commented 7 years ago

I'm not really convinced to for loop nested in do-while loop. I'd rather another array containing already taken int's and checking if picked int is not in that array

Tommac1 commented 7 years ago

do w/e you want

VanDavv commented 6 years ago

@Tommac1 I've changed the code according to your suggestion, thanks!

See: https://github.com/VanDavv/IT-Labs/commit/422d0087a479e09799e90fa2680a1dae04172c21#diff-df9ae53d975af01f807194b866b422e9