昨天加上今天 想把之前学过的链表进行复习一遍 就花了一个下午加一个晚上的时间,把多项式及其计算做一下,然而让人遗憾的是 我一直想用string 来创建一个多项式 结果发现不行 ==
Polynomial.h
#include<iostream>
using namespace std;
struct Term //多项式的节点定义
{
double coef; //系数
int exp; //指数
Term* link;
Term(double a = 0, int b = 0, Term *next = NULL) : coef(a), exp(b), link(next) {}
Term *InsertAfter(double, int);
friend ostream& operator<<(ostream &, const Term &);
};
class Polynomial
{
public:
Polynomial() { head = new Term(); }
Polynomial(Polynomial &);
~Polynomial();
Polynomial & operator = (const Polynomial &);
void PolyClear();
int PolyLength() const;
bool PolyEmpty() const;
bool AddTerm(double const, int const);
void Simplify();
void PolySort();
int maxOrder();
Term * getHead()const { return head; }
friend ostream& operator<<(ostream &, const Polynomial &);
friend ostream& operator>>(istream &, string &);
friend Polynomial& operator+(Polynomial &, Polynomial &);
friend Polynomial& operator*(Polynomial &, Polynomial &);
private:
Term *head;
};
Polynomial.cpp
#include"Polynomial.h"
Term *Term::InsertAfter(double a, int b)
{
link = new Term(a, b, link);
return link;
}
ostream& operator<<(ostream & out, const Term &