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