Answer the question
In order to leave comments, you need to log in
How to rearrange the elements of an array located between its minimum and maximum elements?
Condition: rearrange in reverse order the elements of the array of random numbers located between its minimum and maximum elements. You can only use arrays, conditions, and loops. The bottom line is this: if we have an array of random numbers, let's say: 5, 45, 34, 98, 17, then it will take the form:
5, 34, 45, 98, 17.
Answer the question
In order to leave comments, you need to log in
1 Find the index of the minimum element minIndex
2 Find the index of the maximum element maxIndex
3 Check that there are elements between them
4 Reverse the range from min(minIndex, maxIndex) + 1
to max(minIndex, maxIndex) - 1
Find the index of the minimum and maximum.
If necessary, swap so that one is smaller than the other. INDICES, not elements.
And now the cycle.
++низИндекс
--верхИндекс
пока низИндекс < верхИндекс
поменять a[низИндекс], а[верхИндекс]
++низИндекс
--верхИндекс
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question