# 学习笔记：单链表实现多项式相乘（一）

```while(pList!=NULL){
while(pList2!=NULL){
pNew=(PNODE)malloc(sizeof(NODE));
pNew->pNext=NULL;
pNew->coef=(pList->coef)*(pList2->coef);
pNew->HighPower=(pList->HighPower)+(pList2->HighPower);
pList2=pList2->pNext;
}
pList=pList->pNext;
}```

```#include<stdio.h>
#include<stdlib.h>

typedef struct node{
int coef;
int HighPower;
struct node *pNext;
}NODE,*PNODE;
PNODE crateList();
PNODE caculate(PNODE,PNODE);
PNODE total(PNODE);
PNODE ListFind(PNODE,PNODE);
int main(){
PNODE pList,pList2,pNew;
pList=crateList();
getchar();
pList2=crateList();
pNew=caculate(pList,pList2);
pNew=total(pNew);
return(0);
}
PNODE crateList(){
int a,b,c;
pCurrent=NULL;pPre=NULL;
b=0,c=0;
while(1){
if(scanf("%d %d",&b,&c)!=2)
break;
pCurrent=(PNODE)malloc(sizeof(NODE));
else
pPre->pNext=pCurrent;
pCurrent->pNext=NULL;
pCurrent->coef=b;
pCurrent->HighPower=c;
pPre=pCurrent;
}
puts("input end,now next step");
}
PNODE pCurrent;
pCurrent=pList;
if(pCurrent==NULL)
puts("No Data Record");
else
while(pCurrent!=NULL){
printf("the Coef is %d,and HighPower is %d\n",pCurrent->coef,pCurrent->HighPower);
pCurrent=pCurrent->pNext;
}
}
PNODE caculate(PNODE pList,PNODE pList2){
if(!pList||!pList2){
puts("wrong!");
return(0);
}
while(pList!=NULL){
while(pList2!=NULL){
pNew=(PNODE)malloc(sizeof(NODE));
pNew->pNext=NULL;
pNew->coef=(pList->coef)*(pList2->coef);
pNew->HighPower=(pList->HighPower)+(pList2->HighPower);
pList2=pList2->pNext;
}
pList=pList->pNext;
}
return(pReslut);
}

if(pReslut==NULL){
}
pCurrent=pReslut;
while(pCurrent->pNext!=NULL)
pCurrent= pCurrent->pNext;
}

PNODE  total(PNODE pNew){
pCurrent=pNew;
if(!pNew)
return(0);
pNew3=(PNODE)malloc(sizeof(NODE));
pNew2=(PNODE)malloc(sizeof(NODE));
pNew3->pNext=NULL;
while(pCurrent!=NULL){
pNew3->coef=pCurrent->coef;
pNew3->HighPower=pCurrent->HighPower;
pNew2=ListFind(pNew2,pNew3);
pCurrent=pCurrent->pNext;
}
}

PNODE ListFind(PNODE pNew,PNODE pList){
while(pCurrent!=NULL){
if(pCurrent->HighPower==pList->HighPower){
pCurrent->coef=(pCurrent->coef)*(pList->coef);
pCurrent->HighPower=pCurrent->HighPower+pList->HighPower;
}
pCurrent=pCurrent->pNext;
}
pCurrent=(PNODE)malloc(sizeof(NODE));
else
pPre->pNext=pCurrent;
puts("ok");
pCurrent->pNext=NULL;
pCurrent->coef=pList->coef;
pCurrent->HighPower=pList->HighPower;
pPre=pCurrent;