This function should initialize arrays C[m+1][n+1] and B[m][n] and fill the first row and first column of C with zeros. Note: int*** C refers to a pointer points to the 2D integer array. Please correct the error.
void initLCSTable(int*** C, char*** B, int m, int n)
{
C[m + 1][n + 1] = {{0}}; //i don't know if this makes the 1st row & column to 0
for (int row = 0; row < m; row++)
{
for (int col = 0; col < n; col++)
{
C[m][n] = 0;
}
B[m][n];
}
void printLengthTable(int** C, int m, int n);
void printArrowTable(char** B, int m, int n);
//The following function releases the memory space table C & B
occupied
void freeLCSTable(int** C, char** B, int m)
{
// add code here. Please assist me in this function.
}
main {
int** C;
char** B;
initLCSTable(&C, &B, m, n);
cout << "\nTable C" << endl;
printLengthTable(C, m, n);
cout << "\nTable B" << endl;
printArrowTable(B, m, n);
return 0;
}
//This function print the 2D length array C
//Note: array C has m+1 rows and n+1 column
void printLengthTable(int** C, int m, int n)
{
for (int i = 0; i <= m; i++)
{
for (int j = 0; j <= n; j++)
{
cout << C[i][j] << " ";
}
cout << endl;
}
}
//******************************************
//This function print the 2D arrow array B
//Note: array B has m rows and n column
void printArrowTable(char** B, int m, int n)
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << B[i][j] << " ";
}
cout << endl;
}
}
Output should look like this (ignore the non-zeros since that is a different Longest Subsequence question all together):