V
V
vadimkenny2021-10-08 11:31:27
C++ / C#
vadimkenny, 2021-10-08 11:31:27

How to convert a descending sequence to an ascending one in c++?

It is necessary to write a program in c ++:
In a dynamic array, make increasing sequences from decreasing ones.

For example, the array 5 10 8 3 2 11 9 8 7 after the program is executed should be 5 2 3 8 10 7 8 9 11
That is, the sequences 10 8 3 2 and 11 9 8 7 from were sorted in ascending order. And 5 remained in place

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-10-08
@vadimkenny

1) Iterate through the array, finding descending sequences.
2) Expand each of them.
3) ???
4) PROFIT!
Here's a hint for you on how you can select descending sequences in an array.

start = 0;
while (start < n) {
  end = start;
  ПОКА (start..end+1 - убывающая последовательность) {
    ++end;
  }
  // start..end - убывающая последовательность.
  start = end+1;
}

You can expand a piece from i to j with one while loop. Swap the 2 extreme elements and then it remains to expand the piece from i + 1 to j-1.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question