i need implement assignment operator = on circular linked list , here struct , code far. not sure how copy coefficient , power
struct term { // term on sparce polynomial double coeff; // coefficient of each term int power; // degree of each term term *prev; // pointer previous higher term term *next; // pointer next lower term }; int size; // # terms in sparce polynomial term *head; // pointer doubly-linked circular list of polynomial& polynomial::operator=(const polynomial &rightpoly){ // check self assignment if(&rightpoly !=this){ // clear if(head !=null) delete this; if(rightpoly.head == null) return *this; // make new node head term *ptr = new term; head = ptr; term *curright = rightpoly.head ->next; term *curleft = ptr; // traverse list, making new node , copying data // until rightpoly empty while (curright !=null) { curleft ->next = new term; curleft = curleft ->next; curright = curright ->next; } curleft ->next = null; } return *this; }
Comments
Post a Comment