next up previous contents
Next: Deletion of Terms: Up: Implementation: The Complex_POLY_CELL Class: Previous: The Destructor:

Overloaded Equal:

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



Jim Peterson
1999-04-22