循环两次就是死循环了
#include <stdio.h>
struct Student
{
int nId ;
char cName[50] ;
int nCpp ;
Student *pNext ;
};
Student *pHeader = NULL ;
void main()
{
Student *pNew = new Student ;
int nKey = 0 ;
while(0 == nKey)
{
printf("输入学生的信息:");
scanf("%d %s %d",&pNew->nId,pNew->cName,&pNew->nCpp);
pNew->pNext = NULL ;
if(pHeader == NULL)
{
pHeader = pNew ;
}
else
{
Student *pNode = pHeader ;
for( ;pNode->pNext != NULL ; pNode = pNode->pNext);
pNode->pNext = pNew ;
}
printf("请继续输:");
scanf("%d",&nKey);
}
//显示
Student *pNode = pHeader ;
printf("Id\tName\tCpp\n");
for ( ;pNode != NULL ; pNode = pNode->pNext)
{
printf("%d\t%s\t%d\n",pNode->nId,pNode->cName,pNode->nCpp);
}
pNode = pHeader ;
//释放空间
Student *pTemp = NULL ;
for(pNode=pHeader ; pNode != NULL ; pNode = pTemp )
{
pTemp = pNode->pNext ;
delete pNode ;
}
pHeader = NULL ;
}