原题为PTA数据结构mooc的线性表作业第二题,题目如下:
本人是c++初学者,代码还是感觉有点费劲,大家轻拍砖。整个程序的逻辑就是四个函数组成,分别Read()函数读取输入多项式信息并形成链表,printchain()函数打印链表,chainplus()函数实现两个链表的加法,chainmult()函数实现两个链表的乘法。在设计乘法函数时,在其中也调用了加法函数进行计算。
#include<iostream>
#include<cmath>
using namespace std;
struct node
{
int coe;
int exp;
node* next;
};
node* Read()
{
int n;
cin >> n;
node* head = new node;
node* p = head;
for (int i = 0; i < n; i++)
{
node* temp = new node;
cin >> temp->coe >> temp->exp;
p->next = temp;
p = p->next;
}
p->next = NULL;
return head->next;
}
node* chainplus(node* p1, node* p2)//输入的多项式为降次排序
{
node* p_plus = new node;
node*