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.
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...)
+ 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")