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;

Recommended Answers

I see you crossposted but agree the question is missing input and corresponding output statements.

Jump to Post

All 3 Replies

I see you crossposted but agree the question is missing input and corresponding output statements.

Thanks for your comment. So what do I have to do to fix these mistakes? I'm pretty new at data structures

I see ideas at your cross post. Here and there you didn't share enough code for folk to offer much more.

Remember I will not duplicate answers to what I read at your other discussion. Nod to https://en.wikipedia.org/wiki/Crossposting

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.