写两个有顺序的链表并合并
#include<stdio.h>#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
long num;
int score;
struct student *next;
};
struct student listA,listB;
int n,sum=0;
main()
{
struct student *creat();
struct student *insert(struct student *,struct student *);
void print(struct student *);
struct student *ahead,*bhead,*abh;
printf("input listA:\n");
ahead=creat();
sum=sum+n;
printf("input listB:\n");
bhead=creat();
sum=sum+n;
abh=insert(ahead,bhead);
print(abh);
getch();
}
struct student *creat()
{
struct student *p1,*p2,*head;
n=0;
p1=p2=(struct student *)malloc(LEN);
printf("input number&scores of student:\n");
printf("if number is 0,stop inputing.\n");
scanf("%ld%d",&p1->num,&p1->score);
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student *)malloc(LEN);
scanf("%ld%d",&p1->num,&p1->score);
}
p2->next=NULL;
return head;
}
void print(struct student *head)
{
struct student *p;
printf("\nThere are %d records:\n",sum);
p=head;
if(p!=NULL)
do{
printf("%ld %d\n",p->num,p->score);
p=p->next;
}while(p!=NULL);
}
struct student *insert(struct student *ah,struct student *bh)
{
struct student *pa1,*pa2,*pb1,*pb2;
pa2=pb1=ah;
pb2=pb1=bh;
do{
while((pb1->num>pa1->num)&&(pa1->next!=NULL))
{
pa2=pa1;
pa1=pa1->next;
} /*如果pb1比pa1所指的数大,就不pa1向后移动*/
if(pb1->num<=pa1->num)
{
if(ah==pa1)
ah=pb1;
else
pa2->next=pb1;
pb1=pb1->next;
pb2->next=pa1;
pa2=pb2;
pb2=pb1;
} /*把pb1接到pa中*/
}while((pa1->next!=NULL)||((
pa1==NULL)&&(pb1->next)!=NULL));
if((pb1->num>pa1->num)&&(pa1->next==NULL))
pa1->next=pb1;
return ah;
}
调试时输出
Loaded symbols for 'D:\Debug\hebing.exe'
Loaded 'C:\windows\system32\ntdll.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\kernel32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\advapi32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\rpcrt4.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\secur32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\user32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\gdi32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\imm32.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\lpk.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\usp10.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\apphelp.dll', no matching symbolic information found.
Loaded 'C:\windows\system32\version.dll', no matching symbolic information found.
The thread 0x7D0 has exited with code 0 (0x0).
怎么办啊?源文件好像没错误?