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

📄 76.c

📁 这是一个经过本人一个月的时间自己做的关于c的小程序
💻 C
字号:
#include<stdio.h>
#define datatype char
#include<malloc.h>
typedef struct node
{
	datatype data;
	struct node *next;
}linklist;
linklist *create(linklist *head);   //创建链表
linklist *createA_B(linklist *A,linklist *B);   //两链表的差集
linklist *createAandB(linklist *A,linklist *B);  //两链表的连接
linklist *creatAorB(linklist *A,linklist *B);	//两链表除去相同的部分后 连接
linklist *createAnB(linklist *A,linklist *B);    //两链表的交集;
linklist *createBA(linklist *head);				//链表逆序;


void lianbiao1()
{
	linklist *a,*A,*b,*B,*c,*C;
	a=NULL;
	b=NULL;


	a=create(a);
	A=a;
	getchar();
	printf("A:\n");
	while( a!=NULL )
	{
		printf("%c",a->data);
		a=a->next;
	}
	printf("\n");



	
	b=create(b);
	B=b;
	getchar();
	printf("B:\n");
	while( b!=NULL )
	{
		printf("%c",b->data);
		b=b->next;
	}
	printf("\n");


	c=createA_B(A,B);
	printf("A_B:\n");
	while( c!=NULL )
	{
		printf("%c",c->data);
		c=c->next;
	}
	printf("\n");
	
	C=createAnB(A,B);
	printf("C=AnB:\n");
	while( C!=NULL )
	{
		printf("%c",C->data);
		C=C->next;
	}
	printf("\n");

	c=createAandB(A,B);
	printf("AandB:\n");
	while( c!=NULL )
	{
		printf("%c",c->data);
		c=c->next;
	}
	printf("\n");
	
	c=creatAorB(A,B);
	printf("AorB:\n");
	while( c!=NULL )
	{
		printf("%c",c->data);
		c=c->next;
	}
	printf("\n");



/*	a=createBA(A);
	printf("BA:\n");
	while( a!=NULL )
	{
		printf("%c",a->data);
		a=a->next;
	}
	printf("\n");
	*/
}

linklist *create(linklist *head)
{
	linklist *s,*h1;
	datatype ch;
	head=NULL;
	h1=head;
	ch=getchar();
	while(ch!='#')
	{
		s=(linklist*)malloc(sizeof(linklist));
		s->data=ch;
		if(head==NULL) head=s;
		else h1->next=s;
		h1=s;
		ch=getchar();
	}
	if(h1!=NULL)
		h1->next=NULL;
	return head;
}

linklist *createA_B(linklist *A,linklist *B)
{
	linklist *a,*b,*s;
	linklist *C,*c;
	C=NULL;
	c=C;
	a=A;
	
	while(a!=NULL)
	{
		b=B;
		while(b!=NULL)
		{
			if(b->data==a->data)
				break;
			b=b->next;
		}
		if(b==NULL)
		{
			s=(linklist *)malloc(sizeof(linklist));
			s->data=a->data;
			if(C==NULL) C=s;
			else	c->next=s;
			c=s;
		}
		a=a->next;
	}
	if(c!=NULL)
		c->next=NULL;
	return C;
}

linklist *createAandB(linklist *A,linklist *B)
{
	linklist *C,*a;
	C=NULL;
	a=A;
	C=A;
	while(a->next!=NULL)
	{
		a=a->next;
	}
	a->next=B;

	return C;


}

linklist *creatAorB(linklist *A,linklist *B)
{
	linklist *C,*a,*b,*a1;
	C=NULL;
	a=A;
	b=B;
	while(a!=NULL && a==A )
	{	
		b=B;
		while(b!=NULL)
		{
			if(b->data==a->data)
			{
			break;
			}
			b=b->next;

		}
		if(b!=NULL)
		{
			a=a->next;
			A=a;
		}
		else 
		{
			a1=a;
			a=a->next;
			break;
		}
	}
	while(a!=NULL)
	{
		
		b=B;
		while(b!=NULL)
		{
			if(b->data==a->data)
				break;
			b=b->next;
		}
		if(b!=NULL)
		{
			if(a->next==NULL)
			{
				a1->next=NULL;
				a=a1->next;
			}
			else
			{
				a1->next=a->next;
				a=a1->next;
			}
		}
		else
		{
			a1=a1->next;
			a=a->next;
		}
	}

	C=NULL;
	a=A;
	C=A;
	while(a->next!=NULL)
	{
		a=a->next;
	}
	a->next=B;

	return C;
}

linklist *createAnB(linklist *A,linklist *B)
{
	
	linklist *a,*b,*s;
	linklist *C,*c;
	C=NULL;
	c=C;
	a=A;
	
	while(a!=NULL)
	{
		b=B;
		while(b!=NULL)
		{
			if(b->data==a->data)
				break;
			b=b->next;
		}
		if(b!=NULL)
		{
			s=(linklist *)malloc(sizeof(linklist));
			s->data=a->data;
			if(C==NULL) C=s;
			else	c->next=s;
			c=s;
		}

		a=a->next;
	}
	if(c!=NULL)
		c->next=NULL;
	return C;
}

linklist *createBA(linklist *head)
{
	linklist *p,*q,*r;
	p=head;
	q=p->next;

	while(q!=NULL)
	{
		r=q->next;
		q->next=p;
		if(p==head) 
			p->next=NULL;
		p=q;
		q=r;
	}
	
	head->next=NULL;
	return p;

}

⌨️ 快捷键说明

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