Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Progrmming HELP

1 view
Skip to first unread message

Andytroyp

unread,
Apr 16, 1998, 3:00:00 AM4/16/98
to

I've been working on this problem for days and I keep running into the same
error, no matter how many times I change the code. This function pcombine,
combines like terms of a polynomial. "compair" is the exponent I'm compairing
to "next" if they are the same, I'm adding coefficients and deleting the node
"next". I then set next equal to next->link and compair exponents with
"compair", I do this all the way through the list.
My problem comes when I delete "next". I set next to next->link, which does
work, but then the link of that node is not pointing to the next in the list.
I though I knew what the problem was, I though I wasn't advancing "next"
correctly, but that does seem to work. The pointer "next" does in fact point
to the next in the list, but the link of "next" doesn't point to the node that
follows "next". PLEASE HELP, I can't waste any more time on it, since all the
hours I've spent have not solved the problem. The code for the function
"pcombine" is as follows:

poly_pointer pcombine(poly_pointer d)
{ int exponent;
poly_pointer compair, next, delnode;
compair = d;
exponent = d->expon;

while(compair != NULL)
{ next = compair->link;
while(next !=NULL)
{ if(exponent == next->expon)
{ compair->coef = (compair->coef) + (next->coef);
delnode = next;
compair->link = next->link;
next = next->link;
free(delnode);
}
else
next = next->link;
}
compair = compair->link;
exponent = compair->expon;

}
return d;
} /* end pcombine */

void pdelete(poly_pointer *dptr, poly_pointer delnode, poly_pointer prevnode)
{ if(prevnode == NULL)
*dptr = delnode->link;
else
prevnode->link = delnode->link;
free(delnode);
} /* end pdelete */

andytroy

Kjell-Viggo Løvhaug

unread,
Apr 21, 1998, 3:00:00 AM4/21/98
to

On 16 Apr 1998 15:47:19 GMT, andy...@aol.com (Andytroyp) wrote:

Please show us the declaration for your poly_pointer type.

Kjell-Viggo Løvhaug

0 new messages