交换矩阵中的两行 [英] Swapping two rows in a matrix
本文介绍了交换矩阵中的两行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在交换二维动态数组矩阵中的两行时遇到问题.我想知道是否有直接使用的功能,或者没有,我想知道如何制作.提前致谢. 这是我制作动态数组的方法:
I am having a problem in swapping two rows in a matrix that is a 2D-dynamic array. I wanted to know if there is a function to use directly or if there is none I would like to know how to make one. Thanks in advance. Here is how I made the dynamic array:
int **ptrMatrix = new int*[row];
for (int i = 0; i < row; i++)
ptrMatrix[i] = new int[column];
推荐答案
我找到了解决方案...只需通过创建一个临时变量(X)并应用以下代码即可完成
I found the solution ... it is done simply by making a temporary variable (X) and appling the following code
for (int i=0;i<columns;i++)
{
X=matrix[row1-1][i];
matrix[row1-1][i]=matrix[row2-1][i];
matrix[row2-1][i]=X;
}
这篇关于交换矩阵中的两行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文