C++链表实现一元多项式(加法、减法、乘法)
运行结果如下:
#include<iostream>
using namespace std;
typedef int T;
class Node
{
public:
T coef; //系数
T exp; //指数
Node* next; //指针域
};
class Link
{
public:
Link();
~Link();
void CreatLink();
void ShowLink();
void AddLink(Link& L1, Link& L2);
void SubLink(Link& L1, Link& L2);
void MulLink(Link& L1, Link& L2);
void SortLink(); //按指数排序
private:
Node* L;
T length;
};
Link::Link()
{
L = new Node;
L->next = NULL;
length = 0;
}
void Link::CreatLink()
{
Node* pnew = new Node;
pnew->next = NULL;
cout << "输入系数:" << "