如何交换数组元素以将数组从类似列的表示形式转换为类似行的表示形式 [英] how to swap array-elements to transfer the array from a column-like into a row-like representation
本文介绍了如何交换数组元素以将数组从类似列的表示形式转换为类似行的表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如:数组
a1, a2, a3, b1, b2, b3, c1, c2, c3, d1, d2, d3
代表下表
a1, b1, c1, d1
a2, b2, c2, d2
a3, b3, c3, d3
现在我喜欢把数组变成下面的形式
now i like to bring the array into following form
a1, b1, c1, d1, a2, b2, c2, d2, a3, b3, c3, d3
是否存在一种算法,它将数组(来自第一种形式)和表的维度作为输入参数并将数组转换为第二种形式?我认为一种不需要分配额外内存的算法,相反,我认为应该可以通过元素交换操作来完成这项工作.
Does an algorithm exist, which takes the array (from the first form) and the dimensions of the table as input arguments and which transfers the array into the second form? I thougt of an algorithm which doesn't need to allocate additional memory, instead i think it should be possible to do the job with element-swap operations.
推荐答案
您要查找的术语是就地矩阵转置,这里是 一个实现.
The term you're looking for is in-place matrix transpose, and here's an implementation.
这篇关于如何交换数组元素以将数组从类似列的表示形式转换为类似行的表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文