A. C++设计:一元多项式相加
#include<iostream.h>
#include<malloc.h>
#define len sizeof(LNode)
typedef struct Lnode             //结点结构声明
{       int nf;                  // 多项式系数
	int   ne;                  //多项式幂指数
	struct LNode *next;
 }LNode;
typedef LNode *Pol;
LNode *creat(void)              //创建多项式函数
{ LNode *head,*q;
  LNode *n;
  head=q=n=(LNode *)malloc(len);
  q->next=NULL;
  do{n=(LNode *)malloc(len);
       cin>>n->ne>>n->nf;
       q->next=n;
       q=n;}while(n->nf!=0||n->ne!=0);
    q->next=NULL;
   return head;}
 
LNode *output(LNode *head)  //输出多项式的函数
{LNode *p;
  p=head->next;int n=0;
  if(p->nf==0&&p->ne==0) {cout<<"0";return 0;}
  else do{if(p->nf!=0)
	    {if(n==0)
	      {if(p->ne==0) {cout<<p->nf;break;}
	      else{cout<<p->nf<<"X"<<p->ne;n++;p=p->next;}}
	     else {if(p->ne==0) {if(p->nf<0)cout<<p->nf;else cout<<"+"<<p->nf;break;}
		   else if(p->nf<0) {cout<<p->nf<<"X"<<p->ne;p=p->next;}
		       else {cout<<"+"<<p->nf<<"X"<<p->ne;p=p->next;}}}
	  else p=p->next;}while(p->nf!=0||p->ne!=0);
if(n==0&&p->nf==0&&p->ne==0) {cout<<"0";return 0;}
 return 0;}
LNode * add(Pol &Pa,Pol &Pb)//两个多项式相加的函数
{LNode *p1,*p2,*p,*pr,*p0;
p1=Pa->next;p2=Pb->next;
p0=pr=Pa;
while(p1->next!=NULL||p2->next!=NULL)
{if(p1->ne>p2->ne)
 {pr=p1;p1=p1->next;}
   else if(p1->ne==p2->ne)
        {p1->nf=p1->nf+p2->nf;p2=p2->next;}
          else {pr->next=p2;p2=p2->next; pr=pr->next;pr->next=p1;}
  if(p1->ne==0&&p2->next==NULL) break;}
p1->next=p2;
return p0;
}
void main()//主函数
{char y;
for(;;){Pol p1,p2,p3;
cout<<"input ha"<<endl;
  p1=creat();      //建立多项式HA
cout<<"input hb"<<endl;
  p2=creat();      //建立多项式HB
  cout<<"ha=";*output(p1);cout<<endl;//输出多项式HA
  cout<<"hb=";*output(p2);cout<<endl; //输出多项式HB
  p3=add(p1,p2);  //多项式HA与HB相加
  cout<<"ha+hb=";*output(p3);cout<<endl; 输出多项式HC
 cout<<"ARE YOU CONTINUE?(Y|N)"<<endl;
 cin>>y;
if(y=='n') break;}
B. “一元多项式的表示和相加”数据结构,相关疑问
不会的,因为每个链表每个节点都是一个指针结构
DelFirst()函数是删除当前链表元素。
举个例子
链表节点的定义:
struct node
{
  int val;
  node *next;
};
int DeleteElement(node **head, node *deleteMe)
{
    node *elem = *head;
    if (deleteMe == *head)
    {
        *head = elem -> next;
        free(deleteMe);
        return 1;
    }
    while (elem != NULL)
    {
        if (elem -> next == deleteMe)//不要误写为elem
        {
            elem -> next = deleteMe -> next;   //这里连接链表,链表不会断开
            free(deleteMe);
            return 1;
        }
        elem = elem -> next;
    }
    return 0;
}
C. 一元多项式的相加
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
typedef struct student
{
int coef;
int expn;
struct student *next;
}
plinknode;
plinknode *creat(void)
{
plinknode *head,*p1,*p2,*p3,*p4;
int m,n;
printf("gongyoujiedianshu:");
scanf("%d",&m);
p3=(plinknode *)malloc(sizeof(plinknode));
p3->coef=0;
p3->expn=-1;
p4=p3;
head=p3;
for(n=1;n<=m;n++)
{
p3=(plinknode *)malloc(sizeof(plinknode));
printf("shu,xishu:");
scanf("%d%d",&p3->coef,&p3->expn);
if(p4->expn<p3->expn)
{
p4->next=p3;
p3->next=NULL;
p4=p4->next;
}
else
{
p1=head;p2=p1->next;
while(p2)
{
if(p2->expn==p3->expn)
{
p2->coef=p2->coef+p3->coef;
free(p3);
if(p2->coef==0)
{
p1->next=p2->next;
free(p2);
if(p2->next==NULL)
{
p4=p1;
}
}
break;
}
if(p2->expn>p3->expn)
{
p1->next=p3;
p3->next=p2;
break;
}
p1=p1->next;
p2=p2->next;
}
}
}
return (head);
}
void print(plinknode *p) 
{
plinknode *head;
head=p;
printf("shuchude shi:");
do
{
printf("%d%d\n",head->coef,head->expn);
head=head->next;
}while(head!=NULL);
}
plinknode *add(plinknode *a,plinknode *b)
{
plinknode *head,*p1,*p2,*p3,*p4;
p1=a;
head=a;
p3=b->next;
do
{
p2=p1->next;
if(p2->expn>p3->expn)
{
p1->next=p3;
p4=p3->next;
p3->next=p2;
p3=p4;
p1=p1->next;
}
else if(p2->expn==p3->expn)
{
p2->coef=p3->coef+p2->coef;
if(p2->coef==0)
{
p1->next==p2->next;
free(p2);
p4=p3->next;
free(p3);
p3=p4;
}
else
{
p1=p1->next;
p4=p3->next;
free(p3);
p3=p4;
}
}
else
p1=p1->next;
}while(p1->next!=NULL&&p3!=NULL);
if(p3!=NULL)
{
p2->next=p3;
}
return (head);
}
void main()
{
plinknode *h1,*h2,*h3;
h1=creat();
print(h1);
h2=creat();
print(h2);
h3=add(h1,h2);
print(h3);
}
可以运行,希望对你有帮助
D. 3. 一元多项式的表示和相加(链表,建立,相加,输出)
用链表的网上有,给你个链接,但是正确性我不能保证:
http://..com/question/80603134.html
再给你一个用数组的程序,这个我已在win-tc下调试通过。 
/* 
本题的一个完整的c程序如下,在win-tc和Dev-c++下调试通过。 
需要说明的是这里的m,n表示x的幂分别是m-1次和n-1次, 
同时p[]和q[]的各系数是从x^(m-1)和x^(n-1)到x^0前的系数, 
比如px=3x^3+2x+1,qx=x^2-11x+3,那么m=4,n=3,px和qx的系数分别为 
3,0,2,1和1,-11,3 
*/ 
/*多项式加法程序*/ 
#include <stdio.h> 
#include <stdlib.h> 
#include <math.h> 
#define MAX 50 
void npadd(double p[],int m,double q[],int n,double s[]) 
{ 
int i,j; 
for(i=0;i<m-n;i++) 
s[i]=p[i]; /*计算各项系数*/ 
for (i=m-n,j=0; i<=m-1; i++,j++) 
s[i]=p[i]+q[j]; /*计算各项系数*/ 
return; 
} 
double compute(double s[],int k,double x) /*计算所给多项式的值*/ 
{ 
int i; 
double multip = 1,sum = 0; 
for (i=0;i<k-1;i++) 
multip = multip * x; /*先求出x的最高次项的值*/ 
for (i=0;i<=k-1;i++) 
{ 
sum = sum + s[i] * multip; /*依次从高到低求出相对应次项的值*/ 
if (x!=0) 
multip = multip / x; 
} 
return sum; 
} 
int main() 
{ 
int i,j,m,n; 
double px[MAX],qx[MAX],rx[MAX],x; 
system("cls"); 
for(i=0;i<MAX;i++) 
rx[i]=0; 
puts("Please input two polynomials one by one"); 
puts("P(x)=Pm-1*x^(m-1)+Pm-2*x^(m-2)+...+P1*x+P0"); 
puts("Q(x)=Qn-1*x^(n-1)+Qn-2*x^(n-2)+...+Q1*x+Q0"); 
printf("\nPlease input m (>=1): "); 
scanf("%d",&m); 
printf("Please input P%d, ... P0 one by one:\n",m-1); 
for(i=0;i<m;i++) 
scanf("%lf",&px[i]); 
printf("\nPlease input n (1=<n<=m): ");/* 为简化程序设幂次数低的后输入 */ 
scanf("%d",&n); 
printf("Please input Q%d, ... Q0 one by one:\n",n-1); 
for(i=0;i<n;i++) 
scanf("%lf",&qx[i]); 
npadd(px,m,qx,n,rx); 
printf("\nThe addition of two polynomials R(x) is :\n"); 
for (i=m,j=0;i>=1;i--) /*逐行逐项打印出结果多项式*/ 
{ 
printf(" (%f*x^%d) ",rx[m-i],i-1); 
if(i-1>0) 
printf(" + "); 
else 
printf(" . "); 
if(j==2) 
{ 
printf("\n"); 
j=0; 
} 
else 
j++; 
} 
printf("\n"); 
printf("Input the value of x: "); 
scanf("%lf",&x); 
printf("\nThe value of the R(%f) is: %13.7f\n",x,compute(rx,m,x)); 
system("pause"); 
return 0; 
} 
用数组表示的相乘的地址如下: 
http://..com/question/76281392.html
E. 数据结构 一元多项式求导问题
你的测试数据为什么是0 -1 -1啊?怎么是三个参数啊?不是应该就两个么?一个是系数一个是幂啊!
那这样呢?
==============================================
#include <stdio.h>
#include <malloc.h>
typedef struct polynode
{
  int c;
  int e;
  struct polynode *next;
} poly;
poly *creatpoly()
{
  poly *p,  *q,  *h;
  q = NULL, h = NULL;
  int c;
  int e;
  while (e!=-1)
  {
    scanf("%d%d", &c, &e);          /*将scanf位置改变下*/
    h = (poly*)malloc(sizeof(poly));
    h->c = c;
    h->e = e;
    h->next = NULL;
    if (q == NULL)
      q = h;
    else
      p->next = h;
    p = h;
  }
  return q;
}
poly *qiu(poly *p)
{
  poly *s;
  s = p;
  while (p)
  {
    p->c = (p->c)*(p->e);
    p->e = (p->e) - 1;
    p = p->next;
  }
  return s;
}
void print(poly *p)
{
  int i = 0;
  if (p->e ==  - 1)
  {
    printf("0");
    i++;
  }
  {
    while (p->next != NULL)
    {
      if (p->c != 0)
      {
        printf("%d %d ", p->c, p->e);
        i++;
      }
      else
        ;
      p = p->next;
    }
    if (p->next == NULL)
    {
      if (p->c != 0 && p->e > -1)        /*加上约束条件p->e>-1*/
      {
        printf("%d %d ", p->c, p->e);
        i++;
      }
      else
        ;
    }
    if (i == 0)
      printf("0");
    printf("\n");
  }
}
int main()
{
  poly *d,  *h;
  d = creatpoly();
  h = qiu(d);
  print(h);
  getchar();
  getchar();
  return 0;
}
F. 数据结构,一元多项式的求和问题。
我写的代码写成了两个文件了,
这个是  多项式加法list.h
#include<malloc.h>
typedef struct node
{
   int coef;
   int exp;
   struct node *next;
}listnode;
void creat(listnode *&L)
{
   listnode *p,*q;
   int coef,exp;
   L=(listnode*)malloc(sizeof(listnode));
   p=L;
 
   while(scanf("%d%d",&coef,&exp)==2&&exp>=0)
   {
     q=(listnode*)malloc(sizeof(listnode));
	q->coef=coef;
	q->exp=exp;
	p->next=q;
	p=q;
   }
   p->next=NULL;
}
void print(listnode *L)
{
	listnode *p;
	p=L->next;
   while(p!=NULL)
   {
     if(p->coef!=0)
	{
       printf("[ %d %d ] ",p->coef,p->exp);
	}
	p=p->next;
   }
   printf("\n");
}
void hebing(listnode*&L1,listnode *&L2)
{
   listnode *temp=L1;
   while(temp->next!=NULL)
   {
     temp=temp->next;
   }
   if(L2->next!=NULL)
   {
     temp->next=L2->next;
   }
}
void destroy(listnode *&L)
{
  listnode *p=L,*q=L->next;
  while(q!=NULL)
  {
    free(p);
    p=q;
	q=p->next;
  }
  free(p);
}
void sortadd(listnode *&L)
{
   listnode *p,*q,*pre;
   p=L->next->next;
   L->next->next=NULL;
   while(p!=NULL)
   {
      q=p->next;
	 pre=L;
	 while( pre->next!=NULL && pre->next->exp>p->exp )
	 {
         pre=pre->next;
	 }
      if(pre->next!=NULL&&pre->next->exp==p->exp)
	 {
         pre->next->coef+=p->coef;
		free(p);
         p=q;
	 }
	 else
	 {
         p->next=pre->next;
		pre->next=p;
		p=q;
	 }
   }
}
还有个   多项式加法main
#include<stdio.h>
#include<malloc.h>
#include "list.h"
int main()
{
  listnode *L1=NULL;
  listnode *L2=NULL;
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
   creat(L1);
   creat(L2);
   hebing(L1,L2);
   sortadd(L1);
   print(L1);
 }
  return 0;
}
望采纳谢谢
