I am trying to write a generic matrix Transpose function
void reverse(int** v , int vertexes )
{
for(int i=0;i<vertexes;i++)
for(int j=0;j<vertexes;j++)
{
if(v[i][j] == 1 && v[j][i]==0){
v[j][i] = -1;
v[i][j] = 0;
}
}
for(int i=0;i<vertexes;i++)
for(int j=0;j<vertexes;j++)
{
if(v[i][j] == -1 )
v[i][j] = 1;
}
}
And the main function being
void matrix_graph::process()
{
int v[7][7] = {
{0,1,0,0,0,0,0},
{0,0,1,1,0,0,0},
{1,0,0,0,0,0,0},
{0,0,0,0,1,0,0},
{0,0,0,0,0,1,0},
{0,0,0,1,0,0,1},
{0,0,0,0,0,1,0}
};
reverse(v,7);
}
And i as expected got a
error C2664: 'reverse' : cannot convert parameter 1 from 'int [7][7]' to 'int **'
Is there anything we can do about it?
Is the best we can do to access i
, j
of the passed 2-d array (passing v
as a one dimensional array) is
v[vertexes*i][j]