我想創建一個充滿字符的鏈表。以下代碼僅保存其他所有元素,我可以修改哪些內容以解決此問題?附件是用於讀取用戶輸入的兩種功能。C++鏈表只輸出每隔一個元素
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');
}