// *************************************************** //
//overloading equal operator for CHAR_SLLIST class //
// *************************************************** //
CHAR_SLLIST& CHAR_SLLIST::operator=(const CHAR_SLLIST& B)
{
if (&B != this){
CHAR_SL_CELL *temp,*previous,*again;
if(!(B.head==NULL)){
head->element = B.head->element;
temp = head;
again = B.head->next;
while(!(again==NULL)){
if(temp->next==NULL)
temp->next = new CHAR_SL_CELL(name);
temp->next->element = again->element;
again = again->next;
previous = temp;
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)){
previous = temp;
previous->next = NULL;
delete temp->next;
temp = previous;
}
}
}
return *this;
}