合并2个大小相同且没有额外空间的排序数组
Merge 2 sorted arrays with the same size without extra space?
下面是我要做的一个例子:
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}
您需要std::inplace_merge。见http://www.cplusplus.com/reference/algorithm/inplace_merge/
相关文章:
- 数组不会存储超出第一个空间的范围
- 将数组类型更改为 Int16 会节省存储空间吗?
- 这两个代码之间的差异(为什么我的数组也有额外的空间,即使我限制了它)
- 为多维数组创建内存空间
- 从数组中添加值并插入空间
- 字符串的变体数组包含替代空间
- 读取文件中的数字数量无限,存储在数组中(无空间)
- 动态分配缓冲空间为二维数组 - 为什么失败
- 赋值运算符复制数组中除可用空间之外的所有内容
- C++在具有O(n)空间的数组中查找第一个非重复整数
- 如何为字符串数组实例变量动态分配空间
- 数组的指针,该数组的每个元素的内存空间信息存储在哪里
- 如何将一个巨大的二维数组初始化为类中的空间
- 删除数组中的对象,并通过让其他数组对象相应地向左移动来摆脱空数组空间
- 为什么C++为我的动态数组分配这么大的内存空间
- 看似有效的算法,用于在不浪费空间的情况下将二叉搜索树存储在数组中
- 文本文件读取和动态数组中的 EMTY 空间传递问题
- 将动态空间分配给字符串数组时出现问题
- 追加到具有可用空间的字符数组
- 如何在不分配更多存储空间的情况下从数组初始化向量