它不显示数据,仅显示永无止境的循环

时间:2019-11-14 01:12:34

标签: c++ linked-list

我正在经历一个永无止境的循环。我在此代码中做错了什么?非常感谢您对我的帮助。

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);
} 

1 个答案:

答案 0 :(得分:1)

问题是您将RawKeyboard设置为current
您需要将head->next设置为current

current->next