通过2D阵列的列

问题描述:

让我们说我有一个二维数组,我想通过它的 I 的日柱为排序功能,在一维数组需要并进行排序。
是否可以在没有 C / C ++ 语言复制列到另一个阵列完成。我关注减少时间和空间使用。 (Ofcourse的的复杂的保持不变)

Let's say I have a 2D array and I want to pass it's i th column to a sort function that takes in a 1D array and sorts it. Can it be done without copying the column to another array in C/C++ language. I am concerned about reducing time and space used. (Ofcourse the complexity remains same)

我想通过排序你的意思是的std ::排序从STL,这需要随机访问迭代器。因此,所有你需要做的是提供列迭代器。

I suppose that by sort you mean std::sort from STL, which takes random access iterators. So all you need to do is provide column iterators.

您可以实现一个自己(例如),使用一些迭代器库(即 Boost.Iterator )或使用一些矩阵实现,它提供行/列迭代器。

You can either implement one by yourself (example), use some iterator library (ie. Boost.Iterator) or use some matrix implementation which provides row/column iterators.