template<class theType>
newStudent<theType>* StudentList<theType>::getLocationOfID(const int & target,
newStudent<theType> * theNext)
{
newStudent<theType> * result = NULL;
if(theNext != NULL)
{
if (theNext->getID() == target)
result = theNext;
else
result = getLocationOfID(target, theNext->getNext());
}
else
return result;
} // end recursive getLocationOfID
template<class theType>
bool StudentList<theType>::RemoveAStudent()
{
newStudent<theType> * tmp = head, * prev = head, * curr = head;
bool ableToRemove = true;
int IDtoRemove;
char answer;
//no nodes
if(isEmpty())
{
cout << "\n\t\t No student transcript stored yet"
<< "\n\t\t Please add the student list in order to remove" << endl;
return !ableToRemove;
}
else
{
cout << "\n\t\tWhich student ID would you like "
<< "to remove from the list? ";
cin >> IDtoRemove;
//remove the student located in the head
if(head->getID() == IDtoRemove)
{
counter--;
newStudent<theType> * tmp = head;
head = getLocationOfID(IDtoRemove, head);
delete tmp; //deletes in the head (first Node)
cout << "\n\t\tThe Student Transcript belonging to ID "
<< IDtoRemove << " has been removed.";
return ableToRemove;
}
else
{
newStudent<theType> * tmp = head, * prev = head, * curr = head;
while(curr->getNext() != NULL && curr->getID() != IDtoRemove)
{
prev = curr;
curr = getLocationOfID(IDtoRemove, curr);
}
//removes in the middle
if(curr->getNext() != NULL)
{
counter--;
prev->setNext(curr->getNext());
delete(curr); //delete anywhere in the middle
cout << "\n\t\tThe Student Transcript belonging to ID "
<< IDtoRemove << " has been removed.";
return ableToRemove;
}
else
{
//remove at the end
if(curr->getID() == IDtoRemove)
{
counter--;
prev->setNext(NULL);
delete(curr); //removes last node
cout << "\n\t\tThe Student Transcript belonging to ID "
<< IDtoRemove << " has been removed.";
return ableToRemove;
}
else
cout << "\n\t\tThe ID " << IDtoRemove << " is not in the list.\n";
}
}
}
}
リストからノードを削除しようとすると、削除するたびにクラッシュし、関数printを呼び出して残りのノードをリストに表示します。RemoveAStud()の問題を解決してノードとクラッシュを削除しないでください
私はリストとクラッシュから私はそれを削除するたびにノードを削除し、リスト内の残りのノードを印刷する機能のプリントを呼び出そうと
をこれを理解助けてください。
私はそれが唯一の問題だが、私は薄いそれがクラッシュを説明できる問題だ場合、私は知らない