| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 553 人关注过本帖
标题:[求助我想了好久了还是找不出来 错误
只看楼主 加入收藏
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
 问题点数:0 回复次数:3 
[求助我想了好久了还是找不出来 错误

# 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
feng1256
Rank: 4
等 级:贵宾
威 望:14
帖 子:2899
专家分:0
注 册:2005-11-24
收藏
得分:0 

你的格式看得人郁闷,我整理了下,思路,变量没做任何修改
[CODE]
#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=0;
struct student *head;
struct student *p1,*p2;
float *a,b;

a=&b; /*连接浮点库*/
p1=p2=(struct student *) malloc (LEN);
scanf("%ld,%f",&p1->num,&p1->score);
head=NULL;

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("Input 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("Input the B records:\n");
hB=creat(n);
printf("The B results are:\n");
print(hB);
hC=merge(hA,hB);
printf("\nThe results are :\n");
print(hC); /*这里忘记了释放申请的内存*/
getch(); /*自己加*/
}


[/CODE]


叁蓙大山:工謪、稅務、嗣發 抱歉:不回答女人的问题
2006-04-06 01:10
SunShining
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:31
帖 子:2215
专家分:0
注 册:2006-2-17
收藏
得分:0 

C语言和数据结构冲突吗?~~~

我没细看..你是不是要把俩个表合并后排序..?

scanf("%ld , %f",&p1->num,&p1->score); 注意那个逗号啊.那个你注意了吗?


[glow=255,violet,2]闭关修炼ing...[/glow] [FLASH=360,180]http://www./chinaren.swf[/FLASH]
2006-04-06 01:10
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 
真是高手啊不过我不明白的是WHY要连接浮点数,没有听说过见笑了请指教

明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-04-06 10:25
快速回复:[求助我想了好久了还是找不出来 错误
数据加载中...
 
   



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

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