编译环境:VS2017
#poly.h
#pragma once
#include<iostream>
using namespace std;
class Node
{
public:
int coe;//系数
int ind;//指数
Node *next;
};
class Poly
{
private:
Node *head;
public:
Poly();//创建只有头结点的空链表
void create();//链表赋值
~Poly();//删除链表
Poly(Poly &p);//拷贝构造
Poly & operator=(const Poly & p);//深复制
const Poly operator+(const Poly &p);//合并有序链表
friend ostream & operator<<(ostream &out, const Poly &p);//输出链表
};
#poly.c
#include"poly.h"
Poly::Poly()
{
head=new Node;//定义头结点
head->next = NULL;//将头结点指针域赋值为空
}
void Poly::create()
{
Node *temp = NULL;
int n, coe, ind;
cout << "请输入多项式的项数" << endl;
cin >> n;
cout << "请按指数从大到小的顺序输入" << n << "组元素的系数和指数" << endl;
while (n--)
{
temp = new Node;
cin >> coe