| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 303 人关注过本帖
标题:生成链表的程序,求改错
取消只看楼主 加入收藏
筐筐的橙
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2011-5-31
结帖率:100%
收藏
 问题点数:0 回复次数:0 
生成链表的程序,求改错
typedef struct Polynomial{
    float               coef;     //系数
    int                 expn;     //指数
    struct Polynomial  *next;
}*Polyn,Polynomial;




int m=0,n1=0,n2=0,i=0,a=0,k=0,b=0;
   double xishu;
   int zhishu;
   i=shuru1.GetLength();
   CString hr[10],hr1;
   Polyn pa,pa1;
   Polyn q1,q2;
  
   
   for(;a==0&&b<10;)
   {
       if(shuru1.GetAt(0)=='+')
           {m=0;
            shuru1.Delete(0,1);}
       if(shuru1.GetAt(0)=='-')
           {m=1;
            shuru1.Delete(0,1);}
               n1=shuru1.Find('+');
               n2=shuru1.Find('-');
               if(n1>0&&n2==-1)
                   k=n1;
               if(n2>0&&n1==-1)
                   k=n2;
               if(n1>0&&n2>0)
               {if(n2>n1)
                   k=n1;
               if(n1>n2)
                   k=n2;
               }
               if(n1==-1&&n2==-1)
                   {k=i;
                    a=-1;}

        hr[b]=shuru1.Mid(0,k);
        hr1=hr[b];
             b++;
            
             shuru1.Delete(0,k);



               
   }

pa=(Polyn)malloc(sizeof(struct Polynomial));
        pa->next=NULL;
        for(;b>0;)
            {pa1=(Polyn)malloc(sizeof(struct Polynomial));
             if(hr[b].Find('x')==-1)
                 {pa1->coef=_wtof(hr[b]);
                  pa1->expn=0;}
             else{
                      if(hr[b].Find('x')==0)
                          pa1->coef=1;
                      else
                          pa1->coef=_wtof(hr[b].Mid(0,(hr[b].Find('x'))));}
                       if(m==1)
                          pa1->coef=0-pa1->coef;
                       hr[b].Delete(0,(hr[b].Find('x')));
                       
                       if(hr[b].Find('^')==-1)
                           pa1->expn=1;
                       else
                           {hr[b].Delete(0,2);
                           pa1->expn=_wtof(hr[b].Mid(0,hr[b].GetLength()));}
                    }      //杯具了指数不能为负



                  if(pa1->coef==0) free(pa1);       //系数为0的话释放结点
                  else
                   {
                      Polyn q1,q2;
                      q1=pa;
                      q2=pa->next;
                      while(q2&& pa1->expn < q2->expn)
                       {                        //查找插入位置
                        q1=q2;
                        q2=q2->next;
                        }
                      if(q2&& pa1->expn == q2->expn)
                       {                        //将指数相同相合并
                         q2->coef += pa1->coef;
                         free(pa1);
                         if(!q2->coef)
                          {                    //系数为0的话释放结点
                           q1->next=q2->next;
                           free(q2);
                          }
                        }
                   else
                       {                       //指数为新时将结点插入
                        pa1->next=q2;
                        q1->next=pa1;
                        }
    }
            

mfc写的提取指数和系数并生成指数递减的一元多项式的链表的部分代码,求帮改错
搜索更多相关主题的帖子: double 
2011-11-07 09:50
快速回复:生成链表的程序,求改错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016698 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved