-1

I have a int64_t vector containing N elements that are divided to k ordered segments. e.g if N = 9 and K=3 it can look something like that:

5,6,7,1,2,3,7,8,9

Is there a way to merge the segments in place without first iteratively coping them to another N/K sized arrays and merge?

DsCpp
  • 2,259
  • 3
  • 18
  • 46
  • 1
    What have you tried? Do you have a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) of your attempt to show us? What happens when you build or run your attempt? What do you expect to happen? – Some programmer dude Oct 24 '18 at 13:44
  • 2
    What do you mean by "merge the segments"? –  Oct 24 '18 at 13:48
  • ^^ this and how would you do it **with** first iteratatively copying them to another N/K sized arrays? – 463035818_is_not_an_ai Oct 24 '18 at 13:49
  • Possible duplicate of [How to sort in-place using the merge sort algorithm?](https://stackoverflow.com/questions/2571049/how-to-sort-in-place-using-the-merge-sort-algorithm) – Öö Tiib Oct 24 '18 at 14:00

1 Answers1

1

If you are talking about merge-sorting the segments, then you have std::inplace_merge. Just do it K-1 times with an increasing number of elements in the first range.

Nelfeal
  • 12,593
  • 1
  • 20
  • 39