专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C语言

链表链接有关问题

发布时间:2011-06-28 15:40:39 文章来源:www.iduyao.cn 采编人员:星星草
链表链接问题
#include <stdio.h>
#include <malloc.h>
#define   LON   sizeof(struct   student)
#define   NULL   0
struct   student
{
      int   num;
      int   score;
      struct   student   *next;
};

  int   n;

  void   main()
  {
        struct   student   *head1,*head2,*head;
        struct   student   *creat(void);
        struct   student   *join(struct   student   *head1,struct   student   *head2);
        void   print(struct   student   *head);
        printf( "input   1:\n ");
        head1=creat();
        printf( "input   2:\n ");
        head2=creat();
        head=join(head1,head2);
        print(head);
        getch();
  }


  struct   student   *creat(void)
  {
        struct   student   *head,*p1,*p2;
        n=0;
        p1=p2=(struct   student   *)malloc(LON);
        scanf( "%d%d ",&p1-> num,&p2-> score);
        head=NULL;
        while(p1-> num!=0)
        {
              n=n+1;
              if(n==1)   head=p1;
              else   p2-> next=p1;
              p2=p1;
              p1=(struct   student   *)malloc(LON);
              scanf( "%d%d ",&p1-> num,&p2-> score);
        }
        p2-> next=NULL;
        return(head);
  }

  struct   student   *join(struct   student   *head1,struct   student   *head2)
        {
              struct   student   *p1;
              p1=head1;

              while(p1-> next!=NULL)

                      p1=p1-> next;
                    if(p1-> next==NULL)
                  p1-> next=head2;

                  return(head1);
        }


    void   print(struct   student   *head)
            {
                  struct   student   *p;
                  p=head;

                  while(p!=NULL)
                  {
                        printf( "%d     %d\n ",p-> num,p-> score);
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: