标题:[求助我想了好久了还是找不出来 错误
取消只看楼主
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
 问题点数:0 回复次数:1 
[求助我想了好久了还是找不出来 错误

# include<stdio.h>
# include<stdlib.h>
#include<malloc.h>
# define LEN sizeof(struct student)
struct student
{long num;
float score;
struct student *next;
};


struct student *creat(int x) **创建链表的函数
{ int i;
struct student *head;
struct student *p1,*p2;
p1=p2=(struct student *) malloc (LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;
i=0;
while(i<x)
{ i=i+1;
if(i==1){head=p1; p2=p1;}
else
{p1=(struct student *)malloc(LEN);
scanf("%ld,%f",&p1->num,&p1->score);
p2->next=p1;
p2=p1;}

}
p2->next=NULL;
return(head);

}

void print(struct student *head) **打印函数
{struct student *p;
p=head;
while(p!=NULL)
{printf("%ld,%f\n",p->num,p->score);
p=p->next;
}

}


struct student *merge(struct student *ha,struct student *hb) **让两个表升序 ** 排列

{struct student *hc;
struct student *pc,*p1,*p2;
p1=ha;p2=hb;
if(ha->num < hb->num)
{hc=ha;pc=p1;p1=p1->next;}
else{hc=hb;pc=p2;p2=p2->next;}


do{ if(p1->num < p2->num)
{pc->next=p1;pc=p1;p1=p1->next;}
else{pc->next=p2;pc=p2;p2=p2->next;}
}
while(p1!=NULL && p2!=NULL);

if(p1==NULL) pc->next=p2;
else if(p2==NULL) pc->next=p1;
return(hc);

}


void main() **主函数
{struct student *creat(int);
void print(struct student *);
struct student *merge(struct student *,struct student *);
struct student *hA,*hB,*hC;
int m,n;
printf("Input the No of A line:\n");
scanf("%d",&m);
printf("\nInput the A records:\n");
hA=creat(m);
printf("The A results are:\n");
print(hA);
printf("Input the No of B line:\n");
scanf("%d",&n);
printf("\nInput the B records:\n");
hB=creat(n);
printf("The B results are:\n");
print(hB);
hC=merge(hA,hB);
printf("\n\nThe results are :\n"); 我想用C语言的方法不用数据结构上的知识
print(hC); 谢谢了啊


}

搜索更多相关主题的帖子: include 
2006-04-05 23:08
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
得分:0 
真是高手啊不过我不明白的是WHY要连接浮点数,没有听说过见笑了请指教

明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-04-06 10:25



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




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

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