Trying to implement an assignment operator for a doubly linked list class.
I think part of my problem with this is I do not completely understand how assignment operators work. Here is what I have currently:
//assignment operator
Set& Set::operator=(const Set &rhs){
_head = rhs._head;
_tail = rhs._tail;
//null, basically this object is 0
if(rhs._head == NULL){
_head = NULL;
_tail = NULL;
_size = 0;
}else{
_head = new Elem(*rhs._head);
_tail = new Elem(*rhs._tail);
_size = rhs._size;
Elem *prev = NULL;
Elem *curr = _head;
Elem *otherCurr = rhs._head;
int counter = 0;
while(otherCurr->next != NULL){
curr->next = new Elem(*otherCurr->next);
curr->next->prev = curr;
curr = curr->next;
otherCurr = otherCurr->next;
}
//now that we are done lets setup the tail
_tail->prev = curr;
curr->next = _tail;
}
return *this;
}
Not sure if it will be needed but here is my .h file. The _head and the _tail variables are dummy Elements, and POINT to the first and last elements.
Here is my .h, well just the important part of it:
struct Elem {
ELEMENT_TYPE info;
Elem *prev, *next;
};
Elem *_head, *_tail;
int _size;
Any sort of help would be incredible. At a loss here...