如何通过全名从双向链表中删除重复项 [英] How to remove duplicates from a doubly linked list by full name
问题描述
这是我在RemoveDuplicate的尝试:
// --------------------------------------------- -------------------------------------------------- --------
//名称:RemoveDuplicates。
//说明:搜索列表并查找重复项并删除一个。
// -------------------------------------------- -------------------------------------------------- ---------
void RemoveDuplicates(DoublyLinkedListIterator< Datatype> m_itr,string searchByFirstName)
{
统计播放器;
string playerDuplicate = player.getFirstName();
for(m_itr.Start(); m_itr.Valid(); m_itr.Forth())
{
if(m_itr.Item()。getFirstName()== searchByFirstName)
{
playerDuplicate = m_itr.Item()。getFirstName();
}
}
delete(playerDuplicate);
}
我的统计类有4个成员变量与getter。
private:
string firstName;
string secondName;
int level;
int体验;
在我的链接列表中,我有3个课程。
DoublyLinkedListIterator;
DoublyLinkedList;
DoublyLinkedListNode;
任何帮助都非常感谢。
编辑:后续行动:从DoublyLinkedList中删除重复项
看起来你必须删除链表(使用迭代器)。现在你只是在本地字符串变量playerDuplicate上使用delete。
I have a doubly linked list in which it stores player objects. The player object contains first name, last name, level and experience. Im trying to create a function that will remove a duplicate player object. For instance, if I enter Luis suarez and then he is entered again, I want the function to ask the user to enter the duplicates name and delete one of the luis suarez players (preferably the one last in the list). I've tried many things and none of them work nor delete anything. Can anyone help me with this?
Here is my try at RemoveDuplicate:
// -------------------------------------------------------------------------------------------------------
// Name: RemoveDuplicates.
// Description: Searchs through the list and finds duplicates and removes one.
// -------------------------------------------------------------------------------------------------------
void RemoveDuplicates(DoublyLinkedListIterator<Datatype> m_itr, string searchByFirstName)
{
Stats player;
string playerDuplicate = player.getFirstName();
for (m_itr.Start(); m_itr.Valid(); m_itr.Forth())
{
if (m_itr.Item().getFirstName() == searchByFirstName)
{
playerDuplicate = m_itr.Item().getFirstName();
}
}
delete(playerDuplicate);
}
My stats class has 4 member variables with getters.
private:
string firstName;
string secondName;
int level;
int experience;
In my linked list I have 3 classes.
DoublyLinkedListIterator;
DoublyLinkedList;
DoublyLinkedListNode;
Any help is greatly appreciated.
EDIT: Follow-up: Removing duplicates from a DoublyLinkedList
Looks like you have to delete the actual node in the linked list (using the iterator). Now you are just using delete on the local string variable playerDuplicate.
Full solution in the follow-up.
这篇关于如何通过全名从双向链表中删除重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!