Hey my doubly linked list remove duplictes function will only work when the players in the list are together as in position 1 and 2 or 3 and 4. Otherwise if there not together it will delete the two players. For example, if i have luis suarez at position 1 and have him again at position 3, both luis suarez objects will be deleted when only one is supposed to be removed hence remove duplicate. Here is my code:
void RemoveDuplicates(DoublyLinkedListIterator<Datatype> m_itr, string searchByFirstName, string searchBySecondName)
{
query.clock1();
for(m_itr.Start(); m_itr.Valid(); m_itr.Forth())
{
if ((m_itr.Item().getFirstName() == searchByFirstName )&& (m_itr.Item().getSecondName() == searchBySecondName))
{
//This part was helped by Stack Overflow.
DoublyLinkedListIterator<Datatype> toDelete = m_itr;
m_itr.Forth();
Remove(toDelete);
}
//break;
}
query.clock2();
cout << "\nTime Taken : " << query.time2 - query.time1 << "\n";
}
template <class Datatype>
class DoublyLinkedListIterator
{
public:
//-------------------------------------------------------------------------------------------
// Member Vairables.
//-------------------------------------------------------------------------------------------
DoublyLinkedListNode<Datatype>* m_node; //A node for the Iterator to pointn to.
DoublyLinkedList<Datatype>* m_list; //A list for the Iteraotor to go through.
//-------------------------------------------------------------------------------------------
// Name: Constructor.
// Description: Constructs the DoublyLinkedListIterator.
//-------------------------------------------------------------------------------------------
DoublyLinkedListIterator(DoublyLinkedList<Datatype>* p_list= 0, DoublyLinkedListNode<Datatype>* p_node= 0)
{
m_list= p_list;
m_node= p_node;
}
// ------------------------------------------------------------------
// Name: Start
// Description: Resets the iterator to the beginning of the list.
// Arguments: None.
// Return Value: None.
// ------------------------------------------------------------------
void Start()
{
if(m_list!= 0)
m_node= m_list -> m_head;
}
// ----------------------------------------------------------------
// Name: End
// Description: Resets the iterator to the end of the list.
// Arguments: None.
// Return Value: None.
// ----------------------------------------------------------------
void End()
{
if(m_list!= 0)
m_node = m_list->m_tail;
}
// ----------------------------------------------------------------
// Name: Forth
// Description: Moves the iterator forward by one position.
// Arguments: None.
// Return Value: None.
// ----------------------------------------------------------------
void Forth()
{
if(m_node != 0)
{
m_node = m_node ->m_next;
}
}
// ----------------------------------------------------------------
// Name: Back
// Description: Moves the iterator back by one position.
// Arguments: None.
// Return Value: None.
// ----------------------------------------------------------------
void Back()
{
if(m_node!= 0)
m_node = m_node->m_prev;
}
// ----------------------------------------------------------------
// Name: Item
// Description: Gets the item that the iterator is pointing to.
// Arguments: None.
// Return Value: Reference to the data in the node.
// ----------------------------------------------------------------
Datatype& Item()
{
return m_node->m_data;
}
//-----------------------------------------------------------------
// Name: Valid
// Description: Determines if the node is valid.
// Arguments: None.
// Return Value: true if valid.
// ----------------------------------------------------------------
bool Valid()
{
return (m_node!= 0);
}
};
My program has 3 classes DLLMode, DLLList and DLLIterator. The remove function is in the DoublyLinkedList.h.
Any help is much appreciated