02-线性结构2 一元多项式的乘法与加法运算

02-线性结构2 一元多项式的乘法与加法运算 (20 分)

4 3 4 -5 2 6 1 -2 0
3 5 20 -7 4 3 1

15 24 -25 22 30 21 -10 20 -21 8 35 6 -33 5 14 4 -15 3 18 2 -6 1
5 20 -4 4 -5 2 9 1 -2 0

//写的太乱了/(ㄒoㄒ)/~~
#include<stdio.h>
#include<stdlib.h>
//链表实现
struct node{
int cofe;
int expn;
struct node *next;
};
typedef struct node* Node;
Node Creatlist()//带头结点
{
}
{
Node Newp;
Newp=(Node)malloc(sizeof(struct node));
Newp->cofe=cofe;
Newp->expn=expn;
Newp->next=NULL;
rear->next=Newp;
rear=Newp;
}
{
{
}
}
{
else
{
{
}
printf("\n");
}
}
{
Node List,rear,Newp;
List=(Node)malloc(sizeof(struct node));
List->next=NULL;
{
Newp=(Node)malloc(sizeof(struct node));

{
}
{
}
else
{
}
if(Newp->cofe){
Newp->next=NULL;
rear=Findrear(List);
rear->next=Newp;
rear=Newp;
}
else free(Newp);//系数和为0；
}
{
Newp=(Node)malloc(sizeof(struct node));
Newp->next=NULL;

rear=Findrear(List);
rear->next=Newp;
rear=Newp;

}
{
Newp=(Node)malloc(sizeof(struct node));
Newp->next=NULL;

rear=Findrear(List);
rear->next=Newp;
rear=Newp;

}

return List;
}
int insert(Node List,Node Newp,int cofe,int expn)
{
Node rear;
Newp->cofe= cofe;
Newp->expn=expn;
while(List->next)
{
if(expn==List->next->expn){

if(cofe+(List->next->cofe)==0){
List->next=List->next->next;
}
else {
List->next->cofe=cofe+List->next->cofe;
}
return 1;
}
else if(expn>List->next->expn){//比它大就插在它前面。
Newp->next=List->next;
List->next=Newp;
return 1;
}

List=List->next;
}
rear=Findrear(List);
rear->next=Newp;
rear=Newp;
return 1;

}
{
List=(Node)malloc(sizeof(struct node));
List->next=NULL;    ///新链表
int cofe,expn;

{
{
Newp=(Node)malloc(sizeof(struct node));//现建一个新结点，
Newp->next=NULL;

if(List->next==NULL)
{
Newp->cofe= cofe;
Newp->expn=expn;

List->next=Newp;
Newp->next=NULL;
}
else {

insert(List,Newp,cofe,expn);

}
}

}
return List;
}

int main()
{

int n,m,i,cofe,expn;//n,m分别是项的个数

scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d",&cofe,&expn);
}
scanf("%d",&m);
for(i=0;i<m;i++)
{

scanf("%d %d",&cofe,&expn);
}

print(MultList);
print(MixList);
}

posted @ 2021-08-17 22:31  日月既往、不复可追。  阅读(46)  评论(0编辑  收藏  举报
/*音乐*/ 1 2 3
4