This is my derivative function. This code works correctly but does not delete the constant term. It sets directly to 0 and writes to the result. how can i fix this? Thank you..
EX:
Input: "-x^3-6x^2+ 4x+22"
Output: “-3.0x^2 -12x +4.0 + 0.0”
How can i delete this 0.0?
struct PolyNode {
double coef;
int exp;
struct PolyNode* next;
};
///////////////////////////////////////
PolyNode* Derivative(PolyNode* poly) {
PolyNode* current = new PolyNode;
current = poly;
//Just goes through entire list
while (current != NULL) {
if (current->exp == 0) {
current->coef = 0;
current->exp = 0;
current = current->next;
}
else {
current->coef = current->coef * current->exp;
current->exp = current->exp - 1;
current = current->next;
}
}
return poly;