帮忙看看关于指针的题目的问题出在哪里??
输入输出的结果不一样。。。。。。。#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);
}