Ich versuche eine verknüpfte Liste mit Zeichen zu erstellen. Der folgende Code speichert nur jedes zweite Element. Was kann ich ändern, um das Problem zu beheben? Angeschlossen sind die zwei Funktionen, die beim Lesen der Eingabe vom Benutzer verwendet werden.C++ - verknüpfte Liste gibt nur jedes zweite Element aus
void LList :: InsertTail(element thing) {
// PRE : the N.O. LList is valid
// POST : the N.O. LList is unchanged, except that a
// new listnode containing element thing has been
// inserted at the tail end of the list
listnode * temp;
temp = new listnode;
temp -> data = thing;
temp -> next = NULL;
if(head == NULL)
head = temp;
else
tail -> next = temp;
tail = temp;
}
void LList :: ReadForward() {
// PRE: the N.O. LList is valid
// POST : the N.O. LList is valid, all of its
// previous listnodes have been deleted, and
// it now consists of new listnodes containing
// elements given by the user in foward order
char userval;
Clean();
cout << "Enter the message: ";
userval = cin.get();
cout << userval;
while (cin.get()!= SENTINEL) {
InsertTail(userval);
userval = cin.get();
cout << userval;
}
cin.clear();
cin.ignore(80, '\n');
}