标题:怎么实现两个多项式的除法(用链表实现)???
只看楼主
炫灿星空
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-3-29
 问题点数:0 回复次数:0 
怎么实现两个多项式的除法(用链表实现)???
void polyChu(polynode *A,polynode *B)
 polyptr P = A, Q,L,R,T,C,D;
 polyptr COPYA = NULL,COPYB = NULL;

 if(A->xishu == 0){
  printf("0.\n");
  return ;
 }
 if(B->xishu == 0){
  printf("除数为0,错误!\n");
  return ;
 }
 if(A->xishu < B->xishu){
  printf("商:0,余数为:");
  display(A);
  return ;
 }
 while(NULL != P){
  Q = (polyptr)malloc(sizeof(polynode));
  Q->xishu = P->xishu;
  Q->zhishu = P->zhishu;
  Q->next = NULL;
  if(NULL == COPYA)
   COPYA = Q;
  else
   L->next = Q;
  L = Q;
  P = P->next;
 }
 P = B;
 while(NULL != P){
  Q = (polyptr)malloc(sizeof(polynode));
  Q->xishu = -(P->xishu);
  Q->zhishu = P->zhishu;
  Q->next = NULL;
  if(NULL == COPYB)
   COPYB = Q;
  else
   L->next = Q;
  L = Q;
  P = P->next;
 }
 C = P = Q = L = R = T = NULL

 while(COPYA->zhishu >= COPYB->zhishu){
  D = COPYA;
  while(NULL != D->next)
   D = D->next;
  R = COPYB;
  Q = (polyptr)malloc(sizeof(polynode));
  Q->xishu = (-COPYA->xishu) / R->xishu;
  Q->zhishu = COPYA->zhishu - R->zhishu;
  Q->next = NULL;
  if(NULL == L)
   L = Q;
  else
   P->next = Q;
  P = Q;

  while(NULL != R){
   Q = (polyptr)malloc(sizeof(polynode));
   Q->xishu = P->xishu * R->xishu;
   Q->zhishu = P->zhishu + R->zhishu;
   Q->next = NULL;

   if(NULL == T)
    T = Q;
   else
    C->next = Q;
   C = Q;

   R = R->next;
  }
  D->next = T;

  T = NULL;
  C = NULL;
 }

 printf("A除以B,商:");
 display(L);
 printf("余数:");
 display(COPYA);       请问这个程序怎么才能更完善一下???谢谢了
搜索更多相关主题的帖子: next void display return 多项式 
2012-04-16 09:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-365897-1-1.html




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

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