毕业论文论文范文课程设计实践报告法律论文英语论文教学论文医学论文农学论文艺术论文行政论文管理论文计算机安全
您现在的位置: 毕业论文 >> 课程设计 >> 正文

数据结构课程设计_两个一元稀疏多项式相加 第4页

更新时间:2008-9-9:  来源:毕业论文

两个一元稀疏多项式相加_C语言

源程序清单

#include "stdio.h"

#define LEN sizeof(struct term)

#define NULL 0

 

 struct term{

       int coef;/*系数*/

    struct term *creatpolyn(void){

      struct term *p1,*p2,*head;

      int n,i;

     scanf("%d",&n);

       head=p1=p2=(struct term*)malloc(LEN);

       printf("Decline the sequence importation according to the index number\n");/*按指数降序列输入*/

printf("Input the format is coef,expn \n");/*输入格式是 系数,指数*/

       printf("input 1 term: ");

           scanf("%d,%d",&p1->coef,&p1->expn);

       for(i=2;i<=n;i++){

              p1=(struct term*)malloc(LEN);

              printf("input %d term:",i);

              scanf("%d,%d",&p1->coef,&p1->expn);

              p1->next=NULL;

              p2->next=p1;

              p2=p2->next;

       }/*for*/

  需要完整内容的请联系QQ752018766,本文免费,转发请注明源于www.751com.cn

           n=n+1;

           if(n==1){

           if(p1->expn>p2->expn){

              head=p3=p1;p1=p1->next;

              }/*if*/

else if(p1->expn==p2->expn){

              p1->coef=p1->coef+p2->coef;

           if(p1->coef==0){

                  n=0;p1=p1->next;p2=p2->next;

                         if(!p1)head=p2;

                         if(!p2)head=p1;

                         if(!p1&&!p2){

                                printf("answer is 0\n");

                                head=NULL;}/*if*/

                         }/*if*/

else{

                         head=p3=p1;p1=p1->next;p2=p2->next;

                         }/*else*/

                  }/*else if*/

else{

                  head=p3=p2;p2=p2->next;

                  }/*else*/

                  }/*if*/

                  else{

                         if(p1->expn>p2->expn){

                  p3->next=p1;p1=p1->next;p3=p3->next;

                  }/*if*/

           else if(p1->expn==p2->expn){

                  p1->coef=p1->coef+p2->coef;

                  if(p1->coef==0){

                         p1=p1->next;p2=p2->next;

                         } /*if*/

                  else{

                         p3->next=p1;p1=p1->next;p2=p2->next;p3=p3->next;

                         }/*else*/

                  }/*else if*/

           else{

                  p3->next=p2;p2=p2->next;p3=p3->next;

                  }/*else*/

           } /*else*/

                  }/*while*/

        while(p1!=NULL){

               p3->next=p1;p1=p1->next;p3=p3->next;

               }/*while*/

           while(p2!=NULL){

                  p3->next=p2;p2=p2->next;p3=p3->next;

                  }/*while*/

p3->next=NULL;

           return(head);

 }/*daapolyn*/

 

 struct term *printpolyn(struct term *p){

      int m=0;

while(p!=NULL){

                  m++;

printf("c%d=%d,e%d=%d\n",m,p->coef,m,p->expn);

                  p=p->next;

           }/*while*/

printf("number=%d\n",m);

           }/*printpolyn*/

 

main(){

       struct term *p1,*p2,*head;

       printf("Please input the first formula number: ");/*请输入第一个一元二项式项数*/

                  p1=creatpolyn();

    printf("Please input the second formula number: ");/*请输入第二个一元二项式项数*/

               p2=creatpolyn();

               head=addpolyn(p1,p2);

           printpolyn(head);       

}/*main*/                                        

上一页  [1] [2] [3] [4] 

数据结构课程设计_两个一元稀疏多项式相加 第4页下载如图片无法显示或论文不完整,请联系qq752018766
设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©751com.cn 辣文论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。