#include<stdio.h> #include<malloc.h>
#define Yes 1 typedef struct node { char data; struct node *next; }Snode; void InitStack(Snode *L1) { L1=NULL; } push(Snode *top, char x) { Snode *S; S = (Snode *)malloc(sizeof(Snode)); if (!S) { printf("內存空間不足無法插入! /n"); return 0; } S->data = x; S->next=top; /*新結點鏈入棧頂*/ top = S; /*新結點成爲新的棧頂*/ return 1; } char pop(Snode *top, char e) { Snode * p; if (top!=NULL) { e = top->data; /*原棧頂結點元素賦予e*/ } p=top; /*被刪結點賦予P*/ top=top->next; /*設置新棧頂*/ free(p); /*釋放原棧頂結點內存空間*/ return e; } StackEmpty(Snode *L) { if(L) return 0; else return 1; } char compare() { Snode *L1;
char ch1,ch2,e2,e1; InitStack(L1);
while((ch1=getchar())!='@'||(ch1=getchar())!='&') push(L1,ch1); while((ch2=getchar())=='&') pop(L1,ch2); while(!StackEmpty(L1)) { e1=pop(L1,ch1); e2= pop(L1,ch2); if(e1==e2) continue; else { printf("No/n");break; } } return Yes; }
main() { compare(); printf("/n"); }