| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 488 人关注过本帖
标题:大家帮忙找下错
只看楼主 加入收藏
wrg0709
Rank: 1
来 自:ss
等 级:新手上路
帖 子:81
专家分:0
注 册:2007-12-3
收藏
 问题点数:0 回复次数:1 
大家帮忙找下错
本人用链表 算2个一元多次方程向加的结果
#include<stdio.h>
#include<stdlib.h>
typedef struct a{
struct a *next;
int z;
int x;
}b;
int initiate(b **p)                                    /*声明头结点*/
{
 if((*p=(b *)malloc(sizeof(b)))==NULL)return 0;
 else (*p)->next=NULL; return 1;
}
void insert(b *h)                            /*插入结点*/
{
b *s,*o;
int i,k,j,g;
o=h;  /*j xishu*/
scanf("%d",&k);
printf(" now you have enter %d number\n",k);
for(i=0;i<k;i++)
{
 printf("the %d number: ",i+1);
 scanf("%d %d",&j,&g);
 s=(b *)malloc(sizeof(b));
 s->x=j;s->z=g;s->next=NULL;
 o->next=s;
 o=s;
}
}
void shuchu(b *h)                   /*输出链表*/
{
 b *o,*c;
 o=h->next;
 printf("qian wei xishu hou wei zhishu");
 while(o!=NULL)
 {
   printf("%d%d  ",o->x,o->z);
   o=o->next;
 }
}
void hebing(b *p,b *q)                 /*将俩链表相加*/
{
  b *l,*u,*f,*g;   /* g 释放 l定位*/
u=p->next;f=q->next;
 l=p;
 while(f!=NULL&&u!=NULL)
{
  if(u->z==f->z)
  {
    if(u->x+f->x==0)
     {
         g=u; l->next=u->next; u=u->next;free(g);
         g=f; f=f->next;free(g);
     }
    else
     {
          u->x=(u->x+f->x); l=u;u=u->next;f=f->next;
     }
   }
  elseif((u->z)>(f->z))      /*11111111111111111111111111*/
        {
         g=f; g=g->next;
          f->next=l->next; l->next=f;l=f;
      f=g;
       }
    else
       {l=u; u=u->next; }
  }
 if(u==NULL){
    u=f;
  }

}
main()
{
b *h1,*h2;
int x,y,m,n,k,i;
printf("now we bigain the *head");
if(initiate(&h1)==0){printf("now we are fail the first one"); exit(0);}
if(initiate(&h2)==0){printf("now we are fail the second one"); exit(0);}
printf("enter the first line how many do you want insert please enter with space  the first is xishu\n");
insert(h1);
printf("enter the sencond line how many do you want insert\n");
insert(h2);
printf("now putout the two line");
printf("/*****************************/\n");
shuchu(h1);
printf("/****************************/\n");
shuchu(h2);
printf("/*****************************/\n");
printf("now hebing duoxiangshi");
hebing(h1,h2);
shuchu(h1);
}
最终链表的结果 记在h1上
  错误提示 statement missing ; in function hebing
 但我并没找到哪个地方缺少;
错误位置在我打/*11111111111111111111111111*/的那行
搜索更多相关主题的帖子: 声明 include return number insert 
2008-03-20 17:53
wrg0709
Rank: 1
来 自:ss
等 级:新手上路
帖 子:81
专家分:0
注 册:2007-12-3
收藏
得分:0 
在写hebing这个方法前 我调试过 其他的没问题

程序员的日子就是 泡面+电脑+床
2008-03-20 17:57
快速回复:大家帮忙找下错
数据加载中...
 
   



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

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