私の講師は、関数 remove() を次のように定義しました。
struct node
{
node *next;
int value;
}
int IntList::remove()
{
node *victim = first;
int result;
if(isEmpty()) throw listIsEmpty();
first = victim->next;
result = victim->value;
delete victim;
return result;
}
どこでfirst
「これを表すノードのシーケンスを指しIntList
ます。」
犠牲者と最初の両方が同じものを指している場合、犠牲者を削除すると、これも最初に削除されませんか?