关于链表的问题!
#include <iostream.h>
#include <string.h>
#include <stdlib.h>
#include <iomanip.h>
typedef struct Node //定义一个结点结构类型
{ int num;
char name[10];
float score;
struct Node *next;
} stNode;
stNode *head; //将头指针设为全局变量
void initStLink() //初始化链表
{ head=NULL;
}
void CreateStLink() //创建学生成绩信息链表
{ int num;
char name[10];
float score;
stNode *s,*p;
while(1)
{ s=new stNode;
if(!s)
{cout<<"\nApplition Memory falied!\n";
exit(-1);
}
cout<<"Input num,name,score:\n";
cin>>num>>name>>score;
if(num==0) break;
s->num=num;
strcpy(s->name,name);
s->score=score;
if(!head)
head=s;
else
p->next=s;
p=s;
}
p->next=NULL;
delete s;
}
void dispStLink() //输出链表信息
{stNode *p=head;
cout<<setw(6)<<"num";
cout<<setw(12)<<"name";
cout<<setw(10)<<"score"<<endl;
while(p)
{ cout<<setw(6)<<p->num;
cout<<setw(12)<<p->name;
cout<<setw(10)<<p->score<<endl;
p=p->next;
}
}
void main()
{ initStLink();
CreateStLink();
cout<<"\nCreated StLink List:\n";
dispStLink();
}
上面的程序创建学生成绩信息链表的函数最后释放了s的申请的内存,为什么不会出错而且还能够输出呢?请高手指点