+ 1

How to fill in array while keeping the order still the same?C++

I’ve been struggling with this kind of things. I know how to fill in array then sort it. But how can I fill in array meanwhile keeping the random number being descending order?

18th Nov 2018, 8:15 PM
Jimmy Chen
Jimmy Chen  - avatar
2 Respuestas
0
1)Find max value 2)append to array 3)remove that value from original place 4)loop it Or 1)find max 2)append to array 3)find max and add condition that value isn't in array 4)loop I think second look more complicated, but can have more application Try this.
18th Nov 2018, 8:32 PM
Roneel
Roneel - avatar
+ 1
One possible solution would be to store the random value in a distinct variable and use that variable as the limit for the range you are generating your numbers from. Although then again you'd have to consider how you want to deal with extremely low numbers that occur early on, since they might limit your range too much. I added an example program, but honestly, filling and sorting afterwards seems better to me. This way you cut yourself down to small numbers way too fast most of the time. https://code.sololearn.com/cXo5svg5cuup/?ref=app
18th Nov 2018, 8:34 PM
Shadow
Shadow - avatar