This is a code in C, I need to change the code as much as possible, but on condition to perform the same work as this. Changing the var names and the loops is enough
void ExtractMinimumWeightPath(int path[MAX], int weights[MAX][MAX], int pathWeights[MAX][MAX], int rowc, int colc)
{
int rowsCount = rowc;
int colsCount = colc;
path[rowsCount];
int col = 0;
int i = 0;
for(i=1;i<colsCount;i++)
{
if(pathWeights[rowsCount-1][i]<pathWeights[rowsCount-1][col])
{
col = i;
}
}
int row = rowsCount-1;
do
{
path[row] = col + 1;
if (col>0 && pathWeights[row-1][col-1] + weights[row][col] == pathWeights[row][col])
{
col = col - 1;
}
else if (col < colsCount-1 && pathWeights[row-1][col+1] + weights[row][col] == pathWeights[row][col])
{
col = col + 1;
}
row--;
}
while(row>0);
path[0] = col + 1;
}
This is a code in C, I need to change the code as much as possible, but on condition to perform the same work as this.
Changing the var names and the loops is enough
Step by step
Solved in 2 steps