我需要將所有歌曲的CD添加到集合中。我試圖找出如何從CD集合中刪除CD。例如,當我追加藝術家姓名,CD名稱,標題和每首歌曲的長度並調用顯示功能時,它會顯示所有信息。當我將藝術家,CD的名稱和CD的長度作爲參數調用deleteNode
函數時,顯示功能仍會顯示我附加的內容。該程序的構建良好,但我不認爲我正確調用deleteNode
函數。而且,鏈表具有該類的數據類型。如何刪除節點
該結構
class CD
{
private:
string artist; // To hold artist nam
string name; // To hold name of CD
struct disc
{
string title; // To hold title of the song
double length; // To hold length of the song
}my_disc;
}
調用從主
void remove_cd(LinkedList1<CD> *remove)
{
cout << "Enter the name of the artist of the CD you wish to remove: ";
cin.ignore();
getline(cin, artist);
cout << "Enter the title: ";
cin >> title;
cout << "Enter the length: ";
cin >> length;
CD removeNode(artist, title, length);
remove->deleteNode(removeNode);
}
的deleteNode
功能。如果我使用artist
,name
,並length
)作爲參數deleteNode
我怎麼得到它刪除所有的插入的歌曲也是?我想實際刪除CD
的deleteNode
功能LinkedList的
template <class T>
void LinkedList1<T>::deleteNode(T searchValue)
{
discList **pp = &head;
while (*pp && (*pp)->value != searchValue)
pp = &(*pp)->next;
if (*pp)
{
discList *victim = *pp;
*pp = victim->next;
delete victim;
}
}
重載運營商在CD
bool CD::operator == (const CD &e)
{
if (artist == e.artist)
return true;
return false;
}
bool CD::operator != (const CD &e)
{
if (artist != e.artist)
return true;
return false;
}
我想根據需要使用最小代碼。請告訴我,如果你需要看到更多的代碼。 – Lilspree
看看如何從喜歡的清單數據結構。 – user1929959