// *************************************************** //
//overloading equal operator for CHAR_DLLIST class //
// *************************************************** //
CHAR_DLLIST& CHAR_DLLIST::operator=(const CHAR_DLLIST& B)
{
if (&B != this){
CHAR_DL_CELL *temp,*temp2,*again;
if(!(B.head==NULL)){
if(head==NULL)
head = new CHAR_DL_CELL(name);
head->element = B.head->element;
temp = head;
again = B.head->next;
while(!(again==NULL)){
if(temp->next==NULL){
temp->next = new CHAR_DL_CELL(name);
}
temp->next->element = again->element;
temp2 = temp->next;
temp2->previous = temp;
again = again->next;
temp = temp->next;
}
//we have finished loading the values of B
//check to see if the left side object of the A=B
//still contains more elements. If so, we must
//delete these unwanted cells
if(!(temp->next==NULL)){
temp2 = temp;
temp2->next = NULL;
delete temp->next;
temp = temp2;
end = temp;
}
else{
//all of A is used up -- ie size of A = size of B
//set end cell
end = temp;
head->previous = NULL;
end->next = NULL;
}
}
}
return *this;
}