void display()
{
list *newlist;
newlist = first;
cout << endl;
do
{
if (newlist == NULL)
cout << "List is empty" << endl;
else
{
cout << "Name is: " << newlist->name << " ";
cout << "Age is: " << newlist->age << " ";
cout << "Height is: " << newlist->height;
if (newlist==current)
cout<<" <-- Current position ";
cout<< endl;
newlist = newlist->next;
}
}
while(newlist!=NULL);
cout << "End of List" << endl;
}
我在此处有关当前初始化的帮助下更正了我的整个代码我喜欢这个网站! 就这一个问题 我只想在当前节点显示光标。 但是这段代码甚至没有显示所写的“<--当前位置”。 当我删除“if(newlist==current)”时 所有节点都出现了“<--当前位置”。 所以我有点困惑我应该把它放在哪里...... 我还必须在其他节点之间插入一个节点。 有人可以告诉我如何在我移动电流或电流指向的任何地方显示“当前位置”的代码吗?
最佳答案
该代码应该可以正常工作,如果 current
确实指向列表中的节点之一。
你应该能够通过插入类似的内容来找出答案:
cout << newlist << " " << current << endl;
之前:
newlist = newlist->next;
关于c++ - 帮助显示内容列表 C++ 链表!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5127865/