【数据结构_链表_List_1045】集合的交运算实现


#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
typedef struct node 
{
	int data;
	struct node *next;
}L1,L2;
void startL1(L1 *&LA)
{
	LA=(L1 *)malloc(sizeof(L1));
}
void startL2(L2 *&LB)
{
	LB=(L2 *)malloc(sizeof(L2));
}
void createL1(L1 *&LA,int num1)
{
	L1 *p,*q;
	p=LA;
	for(int i=0;i<num1;i++)
	{
		q=(L1 *)malloc(sizeof(L1));
		cin>>q->data;
		p->next=q;
		p=q;
	}
	p->next=NULL;
}
void createL2(L2 *&LB,int num2)
{
	L2 *r,*s;
	r=LB;
	for(int i=0;i<num2;i++)
	{
		s=(L2 *)malloc(sizeof(L2));
		cin>>s->data;
		r->next=s;
		r=s;
	}
	r->next=NULL;
}
void disp(L1 *&LA,int num1,L2 *&LB,int num2)
{
	L1 *temp1=LA->next;
	L2 *temp2=LB->next;
	int flag=0;
	for(int i=0;i<num1;i++)
	{
		temp2=LB->next;
		flag=0;
		for(int j=0;j<num2;j++)
		{
			if(temp1->data==temp2->data)
			{
				cout<<temp1->data<<" ";
				flag=1;
				temp1=temp1->next;
				break;
			}
			
			temp2=temp2->next;
		}
		if(flag==0) temp1=temp1->next;
	}
}
int main()
{
	int num1,num2;
	cin>>num1;
	L1 *LA;
	L2 *LB;
	startL1(LA);
	createL1(LA,num1);
	cin>>num2;
	startL2(LB);
	createL2(LB,num2);
	disp(LA,num1,LB,num2);
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值