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

📄 集合差.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 subs()
              {
                   node *p,*p1,*p2,*q,*heada,*headb;
                   heada=creatlist();
                   headb=creatlist();
                   p=heada;
                   p1=p;
                   while (p!=NULL)
                   {
                         q=headb;
                         while (q!=NULL && q->data!=p->data)
                         q=q->next;
                         if (q!=NULL){
                                      if (p==heada)
                         {
                                     heada=heada->next;
                                     p1=heada;
                          }
                          else if (p->next==NULL)
                           p1->next=NULL;
                            else p1->next=p->next;
                            p2=p->next;
                            p->next=NULL;
                            free(p);
                            p=p2;
                                     
                         }
                         else 
                         {
                              p1=p;
                              p=p->next;
                              }
                   }
                   p=heada;
                   if (p==NULL)
                   printf("两集合相减结果为空\n");
                   else
                   printf("两集合相减结果为:\n");
                   while (p!=NULL)
                   {
                         printf("%d ",p->data);
                         p=p->next;
                         
                   }
                   }

main()
{
      subs();
      }

⌨️ 快捷键说明

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