未完!

<span style="font-family: Arial, Helvetica, sans-serif;">#include<stdio.h></span>
#include <conio.h>
#include<stdlib.h>
#include<iostream.h>
#define MAXSIZE 100
typedef int ElemType;
typedef struct
{
	ElemType *elem;
	int length;
}SqList;
SqList LA,LB;
void InitList(SqList &LA,SqList &LB)
{
	LA.elem = new ElemType[MAXSIZE];
	LB.elem = new ElemType[MAXSIZE];
	if((!LA.elem)||(!LB.elem))
	{
		cerr<<"存储分配错误!"<<endl;
		exit(1);
	}
	LA.length=0;
	LB.length=0;
}
int Length(SqList &L)
{
	return L.length;
}
int Search(SqList &L,ElemType x)
{
	for (int i=1;i<=L.length;i++)
		if(L.elem[i-1]==x) return i;
		else return 0;
}
bool Insert(SqList &L,int i,ElemType &x)
{
	if(L.length==MAXSIZE) return false;
	if(i<0||i>L.length+1) return false;
	for(int j=L.length;j>=i;j--)
		L.elem[j]=L.elem[j-1];
	L.elem[i-1]=x;
	L.length++;
	return true;
}
void Merge(SqList &LA,SqList &LB)
{/*合并线性表LA与LB,结果存于LA,重复元素只留一个*/
	int n = Length(LA),m = Length(LB);
	int i,k,x;
	for (i=1;i<=m;i++)
	{
		x=LB.elem[i-1];
		k=Search(LA,x);
		if(k==0)
		{
			Insert(LA,n+1,x);
			n++;
		}
	}
}
void main()
{
	SqList LA,LB;
	/*for(int i=1;i<=MAXSIZE;i++)
	{
		scanf("%d", &LA.elem[i-1]);
		getchar(); 
	for(int j=1;j<=MAXSIZE;j++)
	{
		scanf("%d", &LB.elem[j-1]);
        getchar(); */
	/*printf("请输入要插入的数据,以0结束!\n"); 
	ElemType elem;
	scanf("%d",LA.elem);
	while(elem!=00)
	{   
		Insert(LA,1,elem);   
		scanf("%d",LA.elem);
	};
	scanf("%d",LB.elem);
	while(elem!=00)
	{   
		Insert(LB,1,elem);   
		scanf("%d",LB.elem);
	}
	Merge(LA,LB);
	cout<<LA.elem<<endl;
}*/
	LA.elem[1]=7;
	LA.elem[2]=5;
	LA.elem[3]=3;
        LA.elem[4]=11;
	LB.elem[1]=2;
	LB.elem[2]=6;
	LB.elem[3]=3;
	Merge(LA,LB);
	for(int k=0;k<=6;k++)
	printf("%d",LA.elem[k]);
}
  






                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值