| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 951 人关注过本帖
标题:单链表合并
只看楼主 加入收藏
我的手机哦
Rank: 1
等 级:新手上路
帖 子:7
专家分:1
注 册:2011-5-16
结帖率:66.67%
收藏
已结贴  问题点数:5 回复次数:8 
单链表合并
#include "stdio.h"
#include "stdlib.h"
struct node
{
    int data;
    struct node *next;
};
struct node *create()
{
    struct node *h;
    struct node *q;
    int x;
    h=(struct node *)malloc(sizeof(struct node));
    h->next=NULL;
    scanf("%d",&x);
    while(x!=-999)
    {
        q=(struct node *)malloc(sizeof(struct node));
        q->data=x;
        q->next=h->next;
        h->next=q;
        scanf("%d",&x);
    }
    return(h);
}
void outline(struct node *h)
{
    struct node *p;
     p=h->next;
    while(p!=NULL)
    {
        printf("%5d",p->data);
        p=p->next;
    }
   
}
void linkconbine(struct node *h1,struct node *h2)
{
    struct node *p,*q,*r;
    p=h1->next;
    q=h2->next;
    r=h1;
    while(p!=NULL&&q!=NULL)
    {
        if(p->data>=q->data)
        {
            r->next=p;
              r=p;
            p=p->next;
        }
        else
        {
           r->next=q;
             r=q;
           q=q->next;
        }
    }
   
        if(p==NULL)
           r->next=q;
        else if(q==NULL)
           r->next=p;
}
main()
{
    struct node *h1,*h2;
    int x;
    printf("in put the x");
    scanf("%d",&x);
    h1=create();
    printf("input the x");
    scanf("%d",&x);
    h2=create();
   
    linkconbine(h1,h2);
    outline(h1);
}
高手们,是哪里出问题了,为何运行时会出问题呢
        
搜索更多相关主题的帖子: include outline return create while 
2011-10-21 22:25
nomify
Rank: 5Rank: 5
等 级:职业侠客
帖 子:79
专家分:366
注 册:2011-10-13
收藏
得分:2 
啥问题
2011-10-21 22:39
我的手机哦
Rank: 1
等 级:新手上路
帖 子:7
专家分:1
注 册:2011-5-16
收藏
得分:0 
就是合并时 1 2 3 4 5 6 -999
  1 2 3 4 5 6 -999
但是 1 1出现不了
2011-10-24 22:45
lin471306489
Rank: 4
等 级:业余侠客
帖 子:136
专家分:247
注 册:2011-8-16
收藏
得分:2 
这个程序,好难读啊!楼主注意下编程风格,适当注释下!
2011-10-24 23:48
吴军旗
Rank: 5Rank: 5
等 级:职业侠客
帖 子:286
专家分:308
注 册:2011-9-14
收藏
得分:2 
我刚自学完链表,表示爱莫能助。。。。。。。。。

最惨的不是忘不了悲伤的回忆,而是那些悲伤的回忆却开始记不清。。。
2011-10-24 23:51
nomify
Rank: 5Rank: 5
等 级:职业侠客
帖 子:79
专家分:366
注 册:2011-10-13
收藏
得分:0 
把main()里面的两个scanf()去掉呗
2011-10-25 10:08
紫色棒棒糖
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2011-11-16
收藏
得分:0 
主函数main里面的俩个scanf去掉就好了,子函数:struct node *create();中已经有此输入,main中多余
2011-11-21 23:03
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
收藏
得分:0 
大家贴代码都不用 插入代码的方式吗?

女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2011-11-22 00:16
心灵百合
Rank: 5Rank: 5
等 级:职业侠客
帖 子:215
专家分:367
注 册:2011-3-30
收藏
得分:0 
    printf("in put the x");
    scanf("%d",&x);
    h1=create();
    printf("input the x");
    scanf("%d",&x);
    h2=create();
x的值传给那个函数啊!
2011-11-22 19:27
快速回复:单链表合并
数据加载中...
 
   



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

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