请问下面的while(1)和while(head)分别是什么意思啊?#include struct Student{ long num;float score;Student* next;};Student* pHead=NULL; //链首指针void Create(){ Student* pS; //当前插入的结点指针Student* pEnd; //链尾指

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/15 14:10:05

请问下面的while(1)和while(head)分别是什么意思啊?#include struct Student{ long num;float score;Student* next;};Student* pHead=NULL; //链首指针void Create(){ Student* pS; //当前插入的结点指针Student* pEnd; //链尾指
请问下面的while(1)和while(head)分别是什么意思啊?
#include
struct Student
{ long num;
float score;
Student* next;
};
Student* pHead=NULL; //链首指针
void Create()
{ Student* pS; //当前插入的结点指针
Student* pEnd; //链尾指针
pS=new Student; //为第一个结点动态开辟堆内存
cin>>pS->num>>pS->score; //给第一个结点赋值
pHead=pS; //链首指针指向第一个结点
pEnd=pS; //链尾指针指向第一个结点
while(1)
{ pS=new Student; //下一个结点
cin>>pS->num>>pS->score;
if(pS->num==0)
break;
pEnd->next=pS; //原结点
pEnd=pS; //新结点
}
pEnd->next=NULL; //最后结点指针
delete pS;
}
void ShowList(Student* head)
{ cout

请问下面的while(1)和while(head)分别是什么意思啊?#include struct Student{ long num;float score;Student* next;};Student* pHead=NULL; //链首指针void Create(){ Student* pS; //当前插入的结点指针Student* pEnd; //链尾指
while(1)表示从键盘输入来构建链表,直到用户输入num值为0时终止输入.
while(head)表示链表不为空而且没有到达链表尾部时将链表的值输出到标准输出设备(屏幕).