• La=LaULb (循环链表)


    #include<stdio.h>
    typedef struct LNode
    {
    	int data;
    	struct LNode *next;
    }LNode,*LinkList;
    void union1(LinkList &La,LinkList &Lb)
    {
    	LinkList qb;
    	LinkList pa=La->next->next;
    	LinkList pb=Lb->next->next;
    	LinkList rc=La->next;
    	while(pa!=La->next&&pb!=Lb->next)
    	{
    		if(pa->data<pb->data)
    		{
    			rc->next=pa;
    			rc=pa;
    			pa=pa->next;
    		}
    		else if(pa->data>pb->data)
    		{
    			rc->next=pb;
    			rc=pb;
    			pb=pb->next;
    		}
    		else
    		{
    			rc->next=pa;
    			rc=pa;
    			pa=pa->next;
    			qb=pb;
    			pb=pb->next;
    			delete qb;
    		}
    	}
    	if(pb==Lb->next)
    		rc->next=pa;
    	else
    	{
    		LinkList t = La->next ;
    		rc->next=pb;
    		pb=Lb->next;
    		Lb->next= t ;
    		La=Lb;
    	}
    	//  该种方法也可以  else{  Lb->next=La->next;rc->next=pb;La=Lb;}
    	delete pb;
    }
    int main()
    {
    	int m,n,i,a[100],b[100];
    	scanf("%d%d",&m,&n);
    	for(i=0;i<m;i++)
    		scanf("%d",&a[i]);
    	for(i=0;i<n;i++)
    		scanf("%d",&b[i]);
    	LinkList p=new LNode;
    	LinkList La=p;
    	for(i=0;i<m;i++)
    	{
    		LinkList s=new LNode;
    		s->data=a[i];
    		La->next=s;
    		La=s;
    		La->next=p;
    	}
    	LinkList q=new LNode;
    	LinkList Lb=q;
    	for(i=0;i<n;i++)
    	{
    		LinkList s=new LNode;
    		s->data=b[i];
    		Lb->next=s;
    		Lb=s;
    		Lb->next=q;
    	}
    	union1(La,Lb);
    	p=La->next->next;
    	while(p!=La->next)
    	{
    		printf("%d ",p->data);
    		p=p->next;
    	}
    	return 0;
    }

  • 相关阅读:
    vue-cli之加载ico文件
    arcgisJs之featureLayer中feature的获取
    浏览器兼容设置
    global.css
    sass之mixin的全局引入(vue3.0)
    arcgis之隐藏设置放大缩小按钮
    vue之scoped穿透
    关闭google默认打开翻译提醒
    ...args剩余参数用法
    js之向div contenteditable光标位置添加字符
  • 原文地址:https://www.cnblogs.com/NYNU-ACM/p/4237348.html
Copyright © 2020-2023  润新知