Hi I'm currently working on a double ended link list and currently testing it as I implement it.
There are three parts of code I'm Fuzzy on
First is the copy constructor and second is the assignment operator. the third is the implementation of the destroy member function(deleting the list)
Currently this is the implantation I have for the assignment operator.
LinkedList& LinkedList::operator=(const LinkedList& rhs)
{
if(this == &rhs)
return *this;
this->Destroy();
this->mFirst = rhs.mFirst;
this->mLast = rhs.mLast;
return *this;
}
As for the copy constructor, I am not sure how to implement it .
then the destroy member function
void LinkedList::Destroy()
{
LinkedNode* current = nullptr;
if(!IsEmpty())
{
current = mLast->previous;
while(current != nullptr)
{
delete mLast;
current->next = nullptr;
mLast = current;
current = mLast->previous;
}
delete mFirst;
mLast = nullptr;
mFirst = nullptr;
}
}
Here is my Main function
int main()
{
LinkedList list;
list.InsertFirst(5);
list.InsertFirst(24);
list.InsertFirst(32);
LinkedList list2;
list2.InsertFirst(1);
list2.InsertFirst(2);
list2.InsertFirst(3);
list2.InsertFirst(4);
list2.InsertFirst(5);
LinkedNode* current;
current = list.GetFirst();
while (current != nullptr)
{
cout << current->data << endl;
current = current->next;
}
cout << endl;
list = list2;
current = list.GetFirst();
while (current != nullptr)
{
cout << current->data << endl;
current = current->next;
}
cout << endl;
}
now when executing this I get an error: debug assertion failed expression _block_type_is_valid(pHead->nBlockUse)
I'm unsure what this is error is I tried debugging for a while but not sure where things are going wrong. I believe it has something to do with deleting invalid memory.
i know it has something to do with the destroy member function and copy assignment operator, as if i remove list = list2 from the main function everything works fine.
I appreciate any input/help on this






