-5

我有一个在互联网上发现的问题,但它没有最好的解决方案。我的问题是我有一个二维矩阵,我想在第 i 个位置删除一列。例如,矩阵可以表示为 A[2][3]={1,2,3,4,5,6}。我想删除位置 2 的列。所以输出是 B={1,3,4,6}。你能帮我吗?

A=[1 2 3
   4 5 6]

输出

   B=[1 3
      4 6]

功能是

int** delete_column(int** inputMatrix,int position)
{
  //The size of outMatrix must be smaller than inputMatrix

  return outMatrix;
}
4

1 回答 1

0

You can not do this in-place with static arrays in c++. You will need to create another array and copy data there. If you use an array of pointers to dynamic arrays however, you can move the elements in-place and than call realloc to shrink the arrays. You can Also use a vector of vectors and call remove on them.

于 2013-11-04T14:54:59.413 回答