| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1880 人关注过本帖
标题:合并两个链表,可是运行不通过耶~请各位高手帮忙看看错在哪里?
取消只看楼主 加入收藏
风铃之美
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-4-2
收藏
 问题点数:0 回复次数:1 
合并两个链表,可是运行不通过耶~请各位高手帮忙看看错在哪里?
#include "stdio.h"
#include "malloc.h"
 struct node
{
    int data;
    struct node *next;
};

struct node * creat(void)
{
  struct node *p1,*p2,*head;
  p2=p1=(struct node *)malloc(sizeof(struct node));
  scanf("%d",&p1->data);
  head=p1;
  while(p1->data!=NULL)
  {
    p1=(struct node *)malloc(sizeof(struct node));
    scanf("%d",&p1->data);
    p2->next=p1;
    p2=p1;
   }
    p2->next=NULL;
   return(head);
  }
struct node * print(struct node *head)
{
  struct node  *p; int sum=0;
  printf("the data of the list are:\n");
  p=head;
  while(p->next!=NULL)
  {
    printf("%d ",p->data);
    p=p->next;sum++;
  }
}
struct node * connect(struct node *hx,struct node *hy)
{
  struct node *p,*hz;
  p=hx;
  while(p->next!=NULL)
  p=p->next;
  p->next=hy;
  hz=hx;
  return(hz);
  }
main()
{
  struct node *hx,*hy,*hz;
  printf("please enter the data of X");
  hx=creat();
  print(hx);
  printf("please enter the data of Y");
  hy=creat();
  print(hy);
  hz=connect(hx,hy);
  print(hz);
}
搜索更多相关主题的帖子: node 链表 struct head 
2008-04-06 12:46
风铃之美
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-4-2
收藏
得分:0 
上次的问题解决了,您太强了
2008-04-06 15:48
快速回复:合并两个链表,可是运行不通过耶~请各位高手帮忙看看错在哪里?
数据加载中...
 
   



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

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