9.c

来自「数据结构练习共18道。」· C语言 代码 · 共 69 行

C
69
字号
#include <stdio.h>
#include<malloc.h>
typedef struct node{
	char Elem;
	struct node *next;
}Lnode;

void main()
{
	char k;
	Lnode *s,*l,*p,*q,*tail;
	s =(Lnode*) malloc(sizeof (Lnode));
	s->Elem=0;
	s->next=NULL;
	printf("Input the first string:");
	k=getchar();
	while(k!=(char)(10))
	{
		p =(Lnode*) malloc(sizeof (Lnode));
		
		p->Elem=k;
		p->next=NULL;

		if (s->next==NULL)
		{
			s->next = p;
			tail=p;
		}
		else
		{tail->next=p;tail=p;}
		k=getchar();
	}

	l =(Lnode*) malloc(sizeof (Lnode));
	l->Elem=0;
	l->next=NULL;
	printf("Input the second string:");
	k=getchar();
	while(k!=(char)(10))
	{
		p =(Lnode*) malloc(sizeof (Lnode));
		
		p->Elem=k;
		p->next=NULL;

		if (l->next==NULL)
		{
			l->next = p;
			tail=p;
		}
		else
		{tail->next=p;tail=p;}
		k=getchar();
	}
	
	p=s->next;
	q=l->next;

	while(p!=NULL&&q!=NULL)
		if(p->Elem==q->Elem)
		{p=p->next;q=q->next;}
		else {printf("Not equal");return;}


	if(p==NULL&&q==NULL)printf("Equal");

	else printf("Not equal");
}

⌨️ 快捷键说明

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