请问下面的while(1)和while(head)分别是什么意思啊?#include struct Student{ long num;float score;Student* next;};Student* pHead=NULL; //链首指针void Create(){ Student* pS; //当前插入的结点指针Student* pEnd; //链尾指
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/28 06:31:43
![请问下面的while(1)和while(head)分别是什么意思啊?#include struct Student{ long num;float score;Student* next;};Student* pHead=NULL; //链首指针void Create(){ Student* pS; //当前插入的结点指针Student* pEnd; //链尾指](/uploads/image/z/9156990-30-0.jpg?t=%E8%AF%B7%E9%97%AE%E4%B8%8B%E9%9D%A2%E7%9A%84while%EF%BC%881%EF%BC%89%E5%92%8Cwhile%EF%BC%88head%EF%BC%89%E5%88%86%E5%88%AB%E6%98%AF%E4%BB%80%E4%B9%88%E6%84%8F%E6%80%9D%E5%95%8A%3F%23include+struct+Student%7B+long+num%3Bfloat+score%3BStudent%2A+next%3B%7D%3BStudent%2A+pHead%3DNULL%3B+%2F%2F%E9%93%BE%E9%A6%96%E6%8C%87%E9%92%88void+Create%28%29%7B+Student%2A+pS%3B+%2F%2F%E5%BD%93%E5%89%8D%E6%8F%92%E5%85%A5%E7%9A%84%E7%BB%93%E7%82%B9%E6%8C%87%E9%92%88Student%2A+pEnd%3B+%2F%2F%E9%93%BE%E5%B0%BE%E6%8C%87)
请问下面的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)表示链表不为空而且没有到达链表尾部时将链表的值输出到标准输出设备(屏幕).