This is the operator overloading for the polynomials doubly linked list , this code is working fi9 but i m getting repetition like
1x^1 2x^2 when added with 1x^1 3x^6
2x^1 2x^2 3x^6
but i get those terms also which are subtracted already
like i get
1x^1 2x^2 1x^1 3x^6 2x^1 2x^2 3x^6
please kindly help
list operator - (const list& k)
{
node* first;
first = head;
node* second;
second = k.head;
node* result=head;
list r;
while (first != NULL)
{
second=k.head;
while (second != NULL)
{
if (first->exponent == second->exponent )
{
result->coefficient =first->coefficient - second->coefficient;
result->exponent=first->exponent;
r.insert(result->coefficient,result->exponent);
}
else
{
r.insert(second->coefficient, second->exponent);
r.insert(first->coefficient, first->exponent);
}
second=second->next;
}
first=first->next;
}
return r;
}