#include using namespace std; #ifndef NULL // If NULL is not yet defined #define NULL 0 // define it #endif // The bool's that are returned by the methods take value 1 if the // method succeeds and 0 otherwise (if there is overflow, underflow, etc.) struct Monomial { int degree; float coeff; Monomial * next; Monomial(); Monomial(int newdegree, float newcoeff, Monomial * newnext); }; class Polynomial { public: // Creates a zero polynomial Polynomial(); // Frees up memory ~Polynomial(); // Sets the polynomial to 0 bool Init(); // Tests if the polynomial is 0 bool IsZero() const; // Adds the monomial specified to the current polynomial bool AddMonomial(int degree, float coeff); friend void swap(Polynomial & p1, Polynomial & p2); friend ostream &operator<<(ostream & output, const Polynomial & poly); friend istream &operator>>(istream & input, Polynomial & poly); bool operator>(const Polynomial & right) const ; static int GetSwapCount() {return swapCount;} static int GetCompCount() {return compCount;} private: // A polynomial is represented as a linked list of monomials, // ordered from highest degree to lowest. // No monomial in the list may have a zero coefficient. // The 0 polynomial is represented by list=NULL. Monomial * list; static int swapCount; static int compCount; };