⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 集合和.c

📁 数据结构实习 集合和源代码和可执行程序
💻 C
字号:
#include <stdio.h>
#define NULL 0
 typedef struct linknode
 {
         int data;
         struct linknode *next;
         
 }node;
 node *creatlist()
 {
      node *head,*r,*s;
      int x;
      head=(node *)malloc(sizeof(node));
      r=head;
      printf("输入系列整数,以0标志结束\n");
      scanf("%d",&x);
      while(x!=0)
      {
                 s=(node *)malloc(sizeof(node));
                 s->data=x;
                 r->next=s;
                 s->next=NULL;
                 r=s;
                 scanf("%d",&x);
      }
      r->next=NULL;
      s=head;
      head=head->next;
      free(s);
      return(head);
 }
 void adds()
 {
      node *p,*q,*r,*s,*hc,*ha,*hb;
      ha=creatlist();
      hb=creatlist();
      hc=(node *)malloc(sizeof(node));
      r=hc;
      p=ha;
      q=hb;
      while(p!=NULL && q!=NULL)
      {
          if(p->data<q->data)
          {
               s=(node *)malloc(sizeof(node));
               s->data=p->data;
               r->next=s;
               r=s;
               p=p->next;
          }
          else if (p->data>q->data)
          {
               s=(node *)malloc(sizeof(node));
               s->data=q->data;
               r->next=s;
               r=s;
               q=q->next;
          }
          else
          {
              s=(node *)malloc(sizeof(node));
              s->data=q->data;
              r->next=s;
              r=s;
              p=p->next;
              q=q->next;
          }
      }
      if(p==NULL)
      while(q!=NULL)
      {
          s=(node *)malloc(sizeof(node));
          s->data=q->data;
          r->next=s;
          r=s;
          q=q->next;
      }
      if(q==NULL)
      while(p!=NULL)
      {
           s=(node *)malloc(sizeof(node));
           s->data=p->data;
           r->next=s;
           r=s;
           p=p->next;
      }
      r->next=NULL;
      s=hc;
      hc=hc->next;
      free(s);
      s->data;
      s=s->next;
       while(s!=NULL)
      {    
          printf("%d  ",s->data);
          s=s->next;
         
      }
    
 }
 main()
 {
       adds(); 
       
 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -