📄 4-4-2.c
字号:
/*中国系统分析员顾问团,http://www.csai.cn*/
/*程序员下午考试指南书籍源码*/
#include <stdio.h>
#include <malloc.h>
typedef struct lnode {
int tag;
union {
char data;
struct lnode *dlink;
} un;
struct lnode *link;
} listnode;
int equal(listnode *s, listnode *t){
int x;
if(s == t)
return(1);
else if(s != NULL && t != NULL)
if(s->tag == t->tag){
if ( !s->tag )
x = s->un.data == t->un.data ;
else
x = equal(s->un.dlink, t->un.dlink);
if (x) return (equal(s->link, t->link));
}
return(0);
}
main()
{
listnode *a1,*a2,*a3,*b1,*b2,*b3;
a1=(listnode *)malloc(sizeof(listnode));
a2=(listnode *)malloc(sizeof(listnode));
a3=(listnode *)malloc(sizeof(listnode));
a1->tag=0;
a1->un.data='a';
a1->link=a2;
a2->tag=1;
a2->un.dlink=a3;
a2->link=NULL;
a3->tag=0;
a3->un.data='b';
a3->link=NULL;
b1=(listnode *)malloc(sizeof(listnode));
b2=(listnode *)malloc(sizeof(listnode));
b3=(listnode *)malloc(sizeof(listnode));
b1->tag=0;
b1->un.data='a';
b1->link=b2;
b2->tag=1;
b2->un.dlink=b3;
b2->link=NULL;
b3->tag=0;
b3->un.data='c';//把这里的赋值改为'b'时,结果为"Equal!".
b3->link=NULL;
if (equal(a1,b1)) printf("Equal!");
else
printf("Unequal!");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -