【发布时间】:2016-06-19 10:24:07
【问题描述】:
ostream& operator<< (ostream& os,SparseMatrix& m)
{
RowNode* rowPoint = m.rowFront;
Node* point = rowPoint->firstInRow;
while(rowPoint != NULL)
{
while (point != NULL)
{
os << point->row;
os << ' ';
os << point->column;
os << ' ';
os << point->data;
os << endl;
point = point->right;
}
rowPoint = rowPoint->nextRow;
point = rowPoint->firstInRow;
}
os << "0 0 0" << endl;
return os;
}
当我尝试在我的程序中运行它时,列表完全正确,但最后的“0 0 0”行从未出现。我尝试以不同的方式对其进行格式化,将其放在较大的 while 循环末尾的 if 语句中,我什至尝试输出一堆不仅仅是“0 0 0”以查看它是否可以打印任何东西,但没有骰子。
如果有人需要查看更多代码,我很乐意提供!
【问题讨论】:
-
根据您的代码,如果
rowPoint为NULL 或point为NULL,则不会发生打印。我建议使用调试器并观察这两个变量。
标签: c++ linked-list operator-overloading