| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1967 人关注过本帖
标题:小女子作业遇到困难,请各位GG帮忙^~^
取消只看楼主 加入收藏
风铃之美
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-4-2
收藏
 问题点数:0 回复次数:3 
小女子作业遇到困难,请各位GG帮忙^~^
设X=(x1, x2, …, xn)和Y=(y1, y2, …, ym) (m<=n)是两个链式存储的线性表,试把它们合并为一个线性表Z,使得:
Z= (x1,y1,x2,y2,x3,y3,x4,y5,........xm,ym,,xm+1,.....xn)当n>=m时
(x1,y1,x2,y2,x3,y3,x4,y5,........xn,yn,,yn+1,.....ym)当n<m时

要求:
从键盘输入两组整数(每组7~8个数据),分别动态产生带头结点的单链表X和Y,并输出结点值。然后合并为Z,并观察输出结果。
搜索更多相关主题的帖子: 小女子 作业 困难 
2008-04-02 15:05
风铃之美
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-4-2
收藏
得分:0 
第一次编结构体,好多不明白耶。。。最好能有一个答案
2008-04-02 15:40
风铃之美
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-4-2
收藏
得分:0 
好长也,太棒了,我认真研究研究,谢谢您
2008-04-03 12:17
风铃之美
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-4-2
收藏
得分:0 
#include "stdio.h"
#include "malloc.h"
typedef struct node
{
  int data;
  int *next;
  };
 struct node * creat(int n)
{
  struct node *head,*p1,*p2;
  head=(struct node *)malloc(sizeof(struct node));
  head=NULL;
  head->next=p1;                                       /*头指针指向p1*/
  printf("enter data");
  while(p1->data!=NULL)
  {
    p1->next=p2;
    p1=(struct node *)malloc(sizeof(struct node));
    scanf("%d ",&p1->data);
    p2->next=p1;
    }
    return(head);
}
struct node * insert(struct node *x,struct node *y,struct node *z)                                                                                                                                                                                       
{
  struct node *headz;int lx,ly;
  headz=NULL;
  headz->next=z;                                
    if(lx>ly)
  {     
     while(y->next!=NULL)
  {
     z=(struct node *)malloc(sizeof(struct node));
     z->next=x;x=x->next;
     z=(struct node *)malloc(sizeof(struct node));
     z->next=y;y=y->next;
  }
     while(x->next!=NULL)
       {
          z=(struct node *)malloc(sizeof(struct node));
          z->next=x;x=x->next;
         }
   }
   else
   {
   while(x->next!=NULL)
   {
     z=(struct node *)malloc(sizeof(struct node));
     z->next=x;x=x->next;
     z=(struct node *)malloc(sizeof(struct node));
     z->next=y;y=y->next;
  }
  while(y->next!=NULL)
       {
          z=(struct node *)malloc(sizeof(struct node));
          z->next=y;y=y->next;
         }

   }
   return(headz);
}
struct node * print(struct node *z)
{
  do
  {
    printf("%d ",z->data);
    z=z->next;
  }while(z->next!=NULL);
  return(z);
  }
main()
{
  struct node *hx,*hy,*hz;
  int lx,ly;                                     /*输入X,Y的项数即长度*/
  printf("enter lx,ly:\n");                     
  scanf("%d %d",&lx,&ly);                        
  printf("\n creat hx \n");                                       
  hx=struct node * creat(lx);
  print("hx");
  printf("\n creat hy \n");
  hy=struct node * creat(ly);
  print(hy);
  hz=struct node * insert(*hx,*hy,*hz);
  print(hz);
  }
我自己写的,可是老无法通过,而且还有语法错误,可我找不出来了。
2008-04-03 12:51
快速回复:小女子作业遇到困难,请各位GG帮忙^~^
数据加载中...
 
   



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

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