合并具有相同大小的2个排序数组而没有额外空间?

时间:2015-09-22 18:04:53

标签: c++ algorithm sorting

这是我想要做的一个例子:

int size = 10;
int *data = new int[size];

int *array_1 = &data[0];
int *array_2 = &data[size/2];

//fill array_1 and array_2 with data

sort(array_1, array_1+size/2);
sort(array_2, array_2+size/2);

//now, is it possible to merge the 2 sorted arrays?

例如,array_1 = {1, 4, 7}array_2 = {3, 5, 6}

我正在尝试制作data = {1, 3, 4, 5, 6, 7}

1 个答案:

答案 0 :(得分:1)