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,则不会进行打印。我建议使用调试器和*观察*这两个变量。 –