当前位置:首页 > 内蒙古科技大学数据结构课程设计一元多项式的代数运算
#include
struct node{ data dat; node *next; };
int cmp(const void *a,const void *b) {
return ((data*)a)->zhishu-((data*)b)->zhishu; }
void output(node *head) {
node *p;
node *shengxu; shengxu=new node; shengxu->next=NULL; printf(\升序排列\\n\p=head->next; while(p) {
if(p->dat.xishu<0) printf(\ if(p->dat.xishu!=0) {
if(p->dat.xishu==1)
printf(\ else if(p->dat.xishu==-1)
printf(\ else
printf(\ }
node *q; q=new node;
q->dat.zhishu=p->dat.zhishu; q->dat.xishu=p->dat.xishu; q->next=shengxu->next; shengxu->next=q; p=p->next; }
printf(\
printf(\降序排列\\n\ p=shengxu->next; while(p) {
if(p->dat.xishu<0) printf(\ if(p->dat.xishu!=0) {
if(p->dat.xishu==1)
printf(\ else if(p->dat.xishu==-1)
printf(\ else
printf(\ }
p=p->next; }
printf(\}
int main() {
int sum1,sum2; data *d1,*d2;
int zhishu_max1=-1,zhishu_max2=-1; int i,j;
int *biaodashi1,*biaodashi2; node *he,*cha;
node *head1,*head2,*tail1,*tail2; head1=(node *)malloc(sizeof(node)); head2=(node *)malloc(sizeof(node)); head1->next=NULL; head2->next=NULL; tail1=head1; tail2=head2; //
输入第一个表达式
printf(\请输入第一个多项式的项数:\ scanf(\
d1=(data*)malloc(sum1*sizeof(data));
printf(\请依次输入每项多项式的系数和指数:\\n\ for(i=0;i { scanf(\ } // 输入第二个表达式 printf(\请输入第二个多项式的项数:\ scanf(\ d2=(data*)malloc(sum2*sizeof(data)); printf(\ 请依次输入每项多项式的系数和指数:\\n\ for(i=0;i scanf(\ } // 排序 qsort(d1,sum1,sizeof(data),cmp); qsort(d2,sum2,sizeof(data),cmp); zhishu_max1=d1[sum1-1].zhishu; zhishu_max2=d2[sum2-1].zhishu; for(i=0;i<30;i++) printf(\ printf(\ // 输出第一个表达式 printf(\第一个表达式为:\\n\ for(i=0;i if(d1[i].xishu!=0) { if(d1[i].xishu==1) printf(\else if(d1[i].xishu==-1) printf(\ else printf(\ } if(i printf(\ //输出第二个表达式 printf(\第二个表达式为:\\n\ for(i=0;i if(d2[i].xishu!=0) { if(d2[i].xishu==1) printf(\ else if(d2[i].xishu==-1) printf(\ else printf(\ } if(i printf(\ //求两个多项式的和和差 he=new node; cha=new node; he->next=NULL; cha->next=NULL; node *cha_tail,*he_tail; he_tail=he; cha_tail=cha; for(i=0,j=0;i node *p,*p2; p=new node; p2=new node; if(d1[i].zhishu p->dat.zhishu=d1[i].zhishu; p->dat.xishu=d1[i].xishu; p2->dat.zhishu=d1[i].zhishu; p2->dat.xishu=d1[i].xishu; i++; } else if(d1[i].zhishu>d2[j].zhishu) { p->dat.zhishu=d2[j].zhishu; p->dat.xishu=d2[j].xishu; p2->dat.zhishu=d2[j].zhishu; p2->dat.xishu=-d2[j].xishu;
共分享92篇相关文档