I have a code which is programmed in static memory (functions which receive static 2D array) (static code will not compile, 2D array have not dimension) and I need to translate it to dynamic memory with pointers (functions which receive pointers).
The static memory code is:
void mas_corto(unsigned int c[][], unsigned int a[][], int P[][], unsigned int nNodos)
{
int i,j,k;
for (i = 0; i < nNodos; i++){
for(j=0; j < nNodos; j++){
// Inicializamos con el coste de los caminos directos
A[i][j] = C[i][j]; P[i][j] = -1;
}
}
for (k = 0; k < nNodos; k++)
for (i = 0; i < nNodos; i++)
for (j=0; j< nNodos; j++)
if (A[i][k]+A[k][j] < A[i][j])
{
A[i][j] = A[i][k] + A[k][j];
P[i][j] = k;
}
}
void camino (int P[][], int i, int j)
{
int k;
if ((k=P[i][j])== -1)
return;
camino(i,k);
printf("%d",k);
camino(k,j);
}
#define boolean int
void warshall (boolean c[][], boolean a[][], unsigned int nNodos)
{
int i,j,k;
for (i = 0; i < nNodos; i++)
for (j=0; j< nNodos; j++)
A[i][j] = C[i][j];
for (k = 0; k < nNodos; k++)
for (i = 0; i < nNodos; i++)
for (j=0; j< nNodos; j++)
A[i][j] = A[i][j] || A[i][k] && A[k][j];
}
As you can see, functions receive static 2D static array, and I need convert them into 2D pointers like:
void mas_corto(unsigned int **C, unsigned int **A, int **P, unsigned int nNodos)
{
// CODE TRANSLATED
}
void camino (int **P, int i, int j)
{
// CODE TRANSLATED
}
#define boolean int
void warshall (boolean **C, boolean **A, unsigned int nNodos)
{
// CODE TRANSLATED
}
But I do not know how can I translate the code containted inside static function to pointer functions. Any idea how can I achieve that? (I need translate/adpat static in-function code to pointers, in other words, I need fill where // CODE TRANSLATED
appear)
Thank you.