//note that this file is not a complete cc file and won't compile by itself
//You will have to define your struct as well as define a few of the methods
//asked of you on the assignment
//You'll also need to include iostream
void printZeros(int numberZeros);
void printMatrix(MatrixElement* m1)
{
if (m1 == NULL)
{
return;
}
int max = getMaxColumns(m1);
int lastRow = 0;
int lastColumn = -1;
while (m1 != NULL)
{
//first print an appropriate number of 0s.
if (lastRow != m1->row)
{
//finish the line off
printZeros(max - lastColumn);
cout << endl;
//print complete rows of zeros
for (int i=0; i < m1->row - lastRow - 1; i++)
{
printZeros(max);
cout << endl;
}
printZeros(m1->column);
cout << m1->value << " ";
}
else {
printZeros(m1->column - lastColumn - 1);
cout << m1->value << " ";
}
lastRow = m1->row;
lastColumn = m1->column;
m1 = m1->next;
}
//now just finish printing the column
for (int i= lastColumn; i < max; i++)
{
cout << "0 ";
}
cout << endl;
}
void printZeros(int numberZeros)
{
for (int i=0; i < numberZeros; i++)
{
cout << "0 ";
}
}