[英]Sparse Matrix print from linked list
I'm trying to print out the sparse matrix from my linked list. 我正在尝试从链接列表中打印出稀疏矩阵。 That looks like this:
看起来像这样:
0 0 0 0 0 0
1 0 6 0 0 0
4 0 0 0 6 0
But for this, it just prints out 0 with the value inside. 但是为此,它只打印出内部值为0的值。 Here's the codes.
这是代码。
while (temp != NULL)
{
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
if ((row == (temp -> e).getRow()) && (col == (temp -> e).getCol()))
cout << temp ->e.getValue();
else
cout << "0";
}
cout << endl;
}
temp = temp -> next;
}
i
and j
are being incremented. i
和j
正在增加。 Those are the values you need to check against. 这些是您需要检查的值。
You're comparing with row
and col
which are the max values and will never be reached. 您正在与
row
和col
进行比较,这是最大值,将永远无法达到。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.