| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 951 人关注过本帖
标题:单链表合并
取消只看楼主 加入收藏
我的手机哦
Rank: 1
等 级:新手上路
帖 子:7
专家分:1
注 册:2011-5-16
结帖率:66.67%
收藏
已结贴  问题点数:5 回复次数:1 
单链表合并
#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
我的手机哦
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
快速回复:单链表合并
数据加载中...
 
   



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

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