| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 452 人关注过本帖
标题:帮忙看看关于指针的题目的问题出在哪里??
只看楼主 加入收藏
angelakill
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2009-8-25
收藏
 问题点数:0 回复次数:0 
帮忙看看关于指针的题目的问题出在哪里??
输入输出的结果不一样。。。。。。。
#include <stdio.h>
#include <malloc.h>
typedef int Elem;
typedef struct LNode
    {Elem exp;
     Elem date;
     struct LNode *next;
    } LinkList;
Elem judge(LinkList *ha,LinkList *hb)  /*判断指数,并返回值*/
    {LinkList *pa=ha->next;
     LinkList *pb=hb->next;
     if(pa->exp<pb->exp) return 1;
     if(pa->exp=pb->exp) return 0;
     if(pa->exp>pb->exp) return -1;
    }
void DispList(LinkList *L)            /*输出链表*/
    {LinkList *p=L->next;
     while(p->next!=NULL)
        {printf("%dx^%d",L->date,L->exp);
         p=p->next;
        }
     printf("\n");
    }
void CreateListR(LinkList *&L,Elem n)       /*尾插入法  创建链表*/
    {LinkList *p,*s;
     Elem i=0;
     L=(LinkList *)malloc(sizeof(LinkList));
     L->next=NULL;
     p=L;
     while(i<n)
        {    s=(LinkList *)malloc(sizeof(LinkList));
            printf("Please input exp:\n");
            scanf("%d",&(s->exp));
            printf("Please input date:\n");
            scanf("%d",&(s->date));
            p->next=s;
            p=s;
            i++;
        }
     p->next=NULL;
     printf("over\n");
    }
void addList(LinkList *ha,LinkList *hb,LinkList *&hc)  /*系数相加*/
    {LinkList *pa=ha->next;
     LinkList *pb=hb->next;
     LinkList *s,*p;
     hc=(LinkList *)malloc(sizeof(LinkList));
     hc->next=NULL;
     p=hc;
     while(pa->next!=NULL&&pb->next!=NULL)
        { s=(LinkList *)malloc(sizeof(LinkList));
          switch (judge(pa,pb))
            { case 1:s->date=pa->date;
                 s->exp=pa->exp;
                 p->next=s;
                 s->next=NULL;
                 p=s;
                 pa=pa->next;
                 break;
             case 0:s->date=pa->date+pb->date;
                 s->exp=pa->exp;
                 p->next=s;
                 s->next=NULL;
                 p=s;
                 pa=pa->next;
                 pb=pb->next;
                 break;
             case -1:s->date=pb->date;
                 s->exp=pb->exp;
                 p->next=s;
                 s->next=NULL;
                 p=s;
                 pb=pb->next;
                 break;
            }
        }
     if(pb->next!=NULL) pa->next=pb;
     while(pa->next!=NULL)
        {
         s->date=pa->date;
         s->exp=pa->exp;
         p->next=s;
         s->next=NULL;
         p=s;
         pa=pa->next;
        }
    }
void main()
    {    LinkList *ha,*hb,*hc;
        CreateListR(ha,2);
        CreateListR(hb,3);
        DispList(ha);
        DispList(hb);
        addList(ha,hb,hc);
        DispList(hc);
    }
搜索更多相关主题的帖子: 指针 
2009-09-03 18:32
快速回复:帮忙看看关于指针的题目的问题出在哪里??
数据加载中...
 
   



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

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