| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 557 人关注过本帖
标题:小菜~~~~~~求助!!
只看楼主 加入收藏
甲鱼
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-10-4
收藏
 问题点数:0 回复次数:4 
小菜~~~~~~求助!!
各位高手能不能帮我看一下这个程序错在哪了?

#include <stdio.h>
#include <malloc.h>
#define NULL 0
#define LEN sizeof(struct list)
struct list
{
    int num;
    struct list *next;
};
int m,n;
struct list *creat1(void)
{
struct list *head,*p1,*p2;
    n=0;
    p1=p2=(struct list *)malloc(LEN);
    printf("please input the data1:");
    scanf("%ld",&p1->num);
    head=NULL;
    while(p1->num!=0)
    {
        n++;
        if(n==1) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct list *) malloc(LEN);
        scanf("%ld",&p1->num);
    }
    p2->next=NULL;
return(head);
}

struct list *creat2(void)
{
struct list *head,*p1,*p2;
m=0;
p1=p2=(struct list *)malloc(LEN);
    printf("please input the data1:");
    scanf("%ld",&p1->num);
    head=NULL;
    while(p1->num!=0)
    {
        m++;
        if(n==1) head=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct list *) malloc(LEN);
        scanf("%ld",&p1->num);
    }
    p2->next=NULL;
return(head);
}

 void print(struct list *head)
{struct list *p;
p=head;
    do
    {
        printf("%ld",p->num);
        p=p->next;
    }while(p->next!=NULL);  
    printf("%3d",p->num);
    getchar();
 }


struct list *toghter(struct list *head1,struct list *head2)
{
struct list *p1,*p2,*p3,*p4,*head;
    p1=head1;
    p2=head2;
    head=head1;
    while(p1->next!=NULL&&p2->next!=NULL)
    {
        p3=p1->next;
        p4=p2->next;
        p1->next=p2;
        p2->next=p3;
        p1=p3;
        p2=p4;
    }
    if(p1->next==NULL&&p2->next==NULL)
         p1->next=p2;
     if(p1->next==NULL&&p2->next!=NULL)
        p1->next=p2;
    if(p2->next==NULL&&p1->next!=NULL)
    {
        p3=p1->next;p1->next=p2;p2->next=p3;
    }
return(head);
}

 void chain(struct list *head)
{struct list *tmp,*btmp;
int i,min;
for(i=0;i<n+m-1;i++)
{
  tmp=head;
  min=tmp->num;
  btmp=NULL;
  while(tmp->next)
{
if(min>tmp->next->num)
{
min=tmp->next->num;
btmp=tmp;
}
tmp=tmp->next;
}
printf("%d ",min);
}
}

void main()
{
struct list *head1,*head2,*head;
head1=creat1();
head2=creat2();
print(head1);
print(head2);
head=toghter(head1,head2);
chain(head);
}
搜索更多相关主题的帖子: 小菜 
2008-10-04 15:49
守鹤
Rank: 4
来 自:山東臨沂
等 级:贵宾
威 望:12
帖 子:337
专家分:0
注 册:2008-6-20
收藏
得分:0 
1、   #define NULL 0这个语句删掉,系统已经定义了NULL
2、   把void main()改成 main()

多少个日日夜夜想起你,只希望有缘再次相见
2008-10-04 16:47
blueboy82006
Rank: 5Rank: 5
来 自:幻想世界
等 级:贵宾
威 望:16
帖 子:1227
专家分:57
注 册:2007-7-23
收藏
得分:0 
[bo][un]守鹤[/un] 在 2008-10-4 16:47 的发言:[/bo]
2、   把void main()改成 main()


这是什么标准?

2008-10-04 17:33
守鹤
Rank: 4
来 自:山東臨沂
等 级:贵宾
威 望:12
帖 子:337
专家分:0
注 册:2008-6-20
收藏
得分:0 
要看什么样的编译器了

如果在VC++中,当然void main()是正确的了

多少个日日夜夜想起你,只希望有缘再次相见
2008-10-04 17:42
xiaoming8877
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-10-4
收藏
得分:0 
看不懂哦!!!!!

[b]10年的雨水熬成大树,10年的努力创造大成 [/b]
2008-10-05 13:31
快速回复:小菜~~~~~~求助!!
数据加载中...
 
   



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

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