当前位置 :
已知无头单链表A和B表示两个集合,用算法实现A=A-B补集数据结构
1人问答
更新时间:2024-04-26 05:29:55
问题描述:

已知无头单链表A和B表示两个集合,用算法实现A=A-B补集

数据结构

胡振中回答:
  data_int   #include"head.h"   structLNode{   //chardata[10];   intdata;   structLNode*next;   };   typedefstructLNode*LinkList;   voidInitList_L(LinkList&L)//链表构造函数   {   L=newLNode;   L->next=NULL;   }   voidPrintList_L(LinkList&H)//链表显示函数   {   LinkListL=H;   L=L->next;   while(1)   {   cout<<"datavalueis"<<L->data<<endl;   L=L->next;   if(L==NULL)   return;   }   }   voidInsert_L(LinkList&H,intn=0)//插入链表   {   LinkListL=H;   LinkListp=L;   inti=0;   if(n==0)   {   n=1;   while(p->next!=NULL)   {   p=p->next;   n++;   }   }   elseif(n<1)   {   cout<<"error"<<endl;   return;   }   for(i=0;i<n-1;i++)   {   if(L->next==NULL)   {   cout<<"error"<<endl;   return;   }   L=L->next;   }   p=newLNode;   cout<<"pleaseinputavalue:";   cin>>p->data;   p->next=L->next;   L->next=p;   }   LinkListbing_LinkList(LinkLista,LinkListb)   {   LinkListc;   LinkListnc;   LinkListt;   InitList_L(c);   nc=c;   a=a->next;   while(a!=NULL)//复制a到c   {   t=newLNode;   t->data=a->data;   nc->next=t;   t->next=NULL;   nc=nc->next;   a=a->next;   }   b=b->next;   while(b!=NULL)   {   nc=c;   while(nc->next!=NULL)   {   if(nc->next->data==b->data)   break;   nc=nc->next;   }   if(nc->next==NULL)   {   t=newLNode;   t->data=b->data;   nc->next=t;   t->next=NULL;   nc=nc->next;   }   b=b->next;   }   returnc;   }   voidmain()   {   LinkLista,b,c;   inti=0;   InitList_L(a);   cout<<"nIwillinputdate."<<endl;   for(i=1;i<=3;i++)   Insert_L(a,i);   //PrintList_L(a);   InitList_L(b);   cout<<"nIwillinputdate."<<endl;   for(i=1;i<=3;i++)   Insert_L(b,i);   //PrintList_L(b);   c=bing_LinkList(a,b);   PrintList_L(c);   }
最新更新
热门其它
PC端 | 移动端 | mip端
问答网(wenda2.com)汇总了汉语字典,新华字典,成语字典,组词,词语,在线查字典,中文字典,英汉字典,在线字典,康熙字典等等,是学生查询学习资料的好帮手,是老师教学的好助手。
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。

邮箱:联系方式:

Copyright©2009-2021 问答网 wenda2.com 版权所有 闽ICP备2022000227号-1