链表删除和显示问题!
#include "Student.h"
#include <iostream>
#include <string>
using namespace std;
typedef struct ListNode
{
string sID;
string sName;
string bSex;
double Score[2];
ListNode* pNext;
}Node;
class StudentList
{
Node* pHead;
Node* pNew;
Node* pTail;
public:
StudentList(){pHead=NULL;};
Node* ReadStudent(StudentList &list);
void DeleteStudent();
void ShowStudent(StudentList &list);
Node* SelectStudent();
Node* SearchStudent();
};
void StudentList::ShowStudent(StudentList &list)
{
cout<<"ID "<<"Name "<<"Sex "<<"English "<<"Math"<<endl;
Node* p=pHead;
while(p!=NULL)
{
cout<<p->sID<<" "<<p->sName<<" "<<p->bSex<<" "
<<p->Score[0]<<" "<<p->Score[1]<<endl;
p=p->pNext;
}
}
void StudentList::DeleteStudent()
{
string ID;
cout<<"Please input the student's ID"<<endl;
cin>>ID;
Node* pPre;
Node* p=pHead;
while(p!=NULL)
{
pPre=p;
if(ID==p->sID)//因为学号唯一,所以查找到后直接删除,不用继续查找
{
pPre->pNext=p->pNext;
delete p;
cout<<"删除成功!"<<endl;
return;
}
p=p->pNext;
}
cout<<"不存在些学号的学生纪录"<<endl;
}
不用删除功能可以正常显示,当用了删除功能后就不能正常显示了,报错!
...全文


