The current code, that I've given in the previous post, sorts the numbers vector in descending order -- as your assignment seems
You might want to change:
int randomInt = rand() % 20 + -10;
int randomInt = rand() % 21 + -10;
... if you want to include the number 10 as possible numbers.
In this regard, your original code with
boundaries was better, because you had better control over the min/max limits.
Also suggest using at()
if (numbers.at(index) == numbers.at(index-1))
second = numbers.at(index);
Finally, not to scare you, but you'll be in a little trouble if you actually were
required to write your own sorting function. Be mentally prepared for that possible moment, and to defend the usage of std::sort()
, which is what a proficient C++ programmer would use.