• 删除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("
    ") ;
    	return 0;
    }

  • 相关阅读:
    Alpha 冲刺 (4/10)
    福大软工1816 · 团队现场编程实战(抽奖系统)
    Alpha 冲刺 (3/10)
    Alpha 冲刺 (2/10)
    Alpha 冲刺 (1/10)
    福大软工 · 第七次作业
    福大软工 · 第八次作业(课堂实战)- 项目UML设计(团队)
    福大软工1816 · 第六次作业
    福大软工1816 · 第五次作业
    福大软工1816 · 第四次作业
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4237361.html
Copyright © 2020-2023  润新知