0

sorting of an array in c++

the task is to sort an array of random integers in c++ in such a way that the positions of even numbers is not disturbed only the odd numbers are arranges in ascending order.

14th Sep 2019, 8:01 AM
Shivam 256 🇮🇳
Shivam 256 🇮🇳 - avatar
4 ответов
+ 3
the task can be split like this: (I assume the integers are in a range from 0 to n) first we make a list and put all odd elements from the array into that list and set the odd number inside the array to -1. then we sort the list we got. then we go throw the array and everytime we hit a -1 we set it to the next element in the list. hope this helped! happy coding! 😁 (I don't know c++, so this is all I can help you with. I do know Java, but giving you a code that works wouldn't help you become better at such tasks...)
14th Sep 2019, 9:17 AM
Anton Böhler
Anton Böhler - avatar
+ 2
~ swim ~ he wants it so the indexes of even elements don't change ("in such a way that the positions of even numbers is not disturbed")
14th Sep 2019, 10:23 AM
Anton Böhler
Anton Böhler - avatar