请问一下编程高手!

来源:百度知道 编辑:UC知道 时间:2024/06/06 17:56:00
我用VC++6.0编写了一个学生成绩管理程序,用的是带监督元节点的链表,每个学生有一个学号,语文成绩C数学成绩M英语成绩E,体育成绩PE;输入函数creat没有问题,后面print函数是按学号从小到大输出各学生数据,但是程序运行后运行到print后出错,跳出一个对话框要我调试或关闭。
我排序用的是指针,找到链表中最小的一个学号学生,把他从原链表分离出来,放到一个新链表里,以此类推,最后删除原链表,新的链表就是已经拍好序的,然后输出,不过就是运行不了,老师说我指针指乱了,我自己改好久改不出来……
下面是我的程序……

#include<iostream>
#include<string>
using namespace std;
struct stu /*定义结构体变量*/
{
string num;
int C,M,E;
char PE;
stu *next;
};
int main()
{
stu *creat();
stu *print(stu *head);
stu *head,*p;
head=creat();
p=head->next;
head=print(head);

return 0;
}

stu *creat()
{
stu *head,*last,*p;
string x;
head=new stu; /*建立链表的监督元节点head,last是尾指针*/
last=head;
while(1)
{
cout<<"Please input student's number,tupe * to exit."<<endl; /*输入学生数据,按*推出。*/
cin>>x;
if

它死循环了

//while(1)
//{
cout<<"Please input student's number,tupe * to exit."<<endl; /*输入学生数据,按*推出。*/
cin>>x;
if(x != "*")
{
p=new stu;
p->num=x;
cout<<"Please input student's grade(Chinese,Math,English&PE)"<<endl;
cin>>p->C>>p->M>>p->E>>p->PE;
}
//else break;
last->next=p;
last=p;
//}

------------------------------------
for(p1=head;p1->next!=NULL;pre_p1=min,p1=min->next)
/*从头开始到尾巴节点结束(不包括尾巴),pre_p1在每轮循环结束时记录上一轮的最小节点,p1记录最小节点的后一个节点(最小节点一直都是在最前面的)*/
{
min = p1;
POINT *p2;
for(p2=p1; p2->next!=NULL;p2=p2->next)
/*p2后移与min不断进行比较*/
{
if(p2->next->num < min->num)
{
pre_p2=p2;
min=p2->next;