I need to implement the assignment operator = on a circular linked list and here is the struct and my code so far. But i am not sure how to copy the coefficient and the power
struct Term { // a term on the sparce polynomial
double coeff; // the coefficient of each term
int power; // the degree of each term
Term *prev; // a pointer to the previous higher term
Term *next; // a pointer to the next lower term
};
int size; // # terms in the sparce polynomial
Term *head; // a pointer to the doubly-linked circular list of
Polynomial& Polynomial::operator=(const Polynomial &rightpoly){
// check for self assignment
if(&rightpoly !=this){
// clear this
if(head !=NULL)
delete this;
if(rightpoly.head == NULL)
return *this;
// make new node for the head
Term *ptr = new Term;
head = ptr;
Term *curRight = rightpoly.head ->next;
Term *curLeft = ptr;
// traverse the list, making a new node and copying data
// until rightpoly is empty
while (curRight !=NULL) {
curLeft ->next = new Term;
curLeft = curLeft ->next;
curRight = curRight ->next;
}
curLeft ->next = NULL;
}
return *this;
}