删除Lb重复的数,用La输出(顺序表)

#include<stdio.h>
typedef int A;
const int LIST_INIT_SIZE=100;
const int LISTINCRMENT=10;
typedef struct
{
	A *elem;
	int Length;
	int Listsize;
	int incrementsize;
}List;
void InitList(List &L,int maxsize=LIST_INIT_SIZE,int incresize=LISTINCRMENT)
{
	L.elem=new A[maxsize];
	L.Length=0;
	L.Listsize=maxsize;
	L.incrementsize=incresize;
}
bool ListEmpty(List &L)
{
	if(L.Length==0)
		return true;
	else
		return false;
}
void ListDelete(List &L,int i,A &e)
{
	A *p,*q;
	if((i<1)||(i>L.Length))
		printf("i值不合法");
	p=&(L.elem[i-1]);
	e=*p;
	q=L.elem+L.Length-1;
	for(++p;p<=q;++p)
		*(p-1)=*p;
	--L.Length;
}
int LocateElem(List L,A e)
{
	int *p;
	int i=1;
	p=L.elem;
	while(i<=L.Length&&*p++!=e)
		++i;
	if(i<=L.Length)
		return i;
	else
		return 0;
}
void increment(List &L)
{
	A *a;
	a=new A[L.Listsize+L.incrementsize];
	for(int i=0;i<L.Length;i++)
		a[i]=L.elem[i];
	delete[]L.elem;
	L.elem=a;
	L.Listsize+=L.incrementsize;
}
void ListInsert(List &L,int i,A e)
{
	A *p,*q;
	if(i<1||i>L.Length+1)
		printf("i值不合法");
	if(L.Length>=L.Listsize)
		increment(L);
	q=&(L.elem[i-1]);
	for(p=&(L.elem[L.Length-1]);p>=q;--p)
		*(p+1)=*p;
	*q=e;
	++L.Length;
}
void DestroyList(List &L)
{
	delete[]L.elem;
	L.Listsize=0;
	L.Length=0;
}
void purge(List &La,List &Lb)
{
	int e;
	InitList(La);
	int La_len=0;
	while(!ListEmpty(Lb))
	{
		ListDelete(Lb,1,e);
		if(!LocateElem(La,e))
			ListInsert(La,++La_len,e);
	}
	DestroyList(Lb);
}
int main()
{
	List a,b;
	InitList(b);
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&b.elem[i]);
		b.Length++;
	}
	purge(a,b);
	for(i=0;i<a.Length;i++)
		printf("%d ",a.elem[i]);
	printf("\n") ;
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值