首页 > 解决方案 > 它不显示数据,它只显示永无止境的循环

问题描述

我得到了一个永无止境的循环。我在这段代码中做错了什么?非常感谢你帮助我。

void viewStudents()
{
    student *current = head;
    do
    {
        if(current == NULL)
            cout<<"Nothing here."<<endl;
        else
        {
        cout<<"Student Name: "<<current->name<<endl;
        cout<<"Student's ID Number: "<<current->studentNum<<endl;
        cout<<"Student Degree: "<<current->studentDeg<<endl;
        cout<<"Student Year Level: "<<current->studentYearLvl<<endl;
        cout<<"Student Contact Number: "<<current->studentCont<<endl;
        cout<<"Student Email: "<<current->studentEmail<<endl;
        cout<<endl;
        current = head->next;
        }
    }
    while(current != NULL);
} 

标签: c++linked-list

解决方案


问题是您一直设置currenthead->next.
你想要的是设置currentcurrent->next

current = current->next;

推荐阅读