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

📄 1顺序表合并.cpp

📁 数据结构的C++表述
💻 CPP
字号:
#include <iostream.h>
#define MaxSize 100
struct seqlist
{
	int data[MaxSize];
	int last;
};
void Input(seqlist *A,int n)
{
	for(int i=0;i<n;i++)
		cin>>A->data[i];
	A->last=n-1;
}
void Print(seqlist *A)
{
	for(int i=0;i<=A->last;i++)
		cout<<A->data[i]<<" ";
	cout<<endl;
}
int Union(seqlist *La,seqlist *Lb)
{		
	int i,j,flag;
	if(La->last+1+Lb->last+1>MaxSize)
			return(-1);
	for(i=0;i<=Lb->last;i++)
	{
		flag=1;
		for(j=0; j<=La->last; j++)
			if(Lb->data[i]==La->data[j])
			{
				flag=0;
				break;
			}
		if(flag==0)
			j++;
		if(flag!=0)
			La->data[++La->last]=Lb->data[i];
	}
	return 1;
} 
void main()
{
	seqlist s1,s2;
	int n1,n2;
	cout<<"输入顺序表s1和s2的元素个数:";
	cin>>n1>>n2;
	cout<<"输入s1中的数据:";
	Input(&s1,n1);
	cout<<"输入s2中的数据:";
	Input(&s2,n2);
	cout<<"s1中的数据为:";
	Print(&s1);
	cout<<"s2中的数据为:";
	Print(&s2);
	Union(&s1,&s2);
	cout<<"合并后s1中的数据为:";
	Print(&s1);
}

⌨️ 快捷键说明

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