学习代码5

include

include

include

include

define TRUE 1

define ERROR 0

define Max 100

typedef char Elemtype;
typedef struct Node{
Elemtype data;
struct Node next;
}StackNode,
LinkStack;

void InitLinkStack(LinkStack *L){
L=(LinkStack)malloc(sizeof(StackNode));
(
L)->next=NULL;
}

int pop(LinkStack L,Elemtype *e);
int decide(LinkStack L,Elemtype a[Max]);
int Input(LinkStack L);
void push(LinkStack L,Elemtype a[Max]);

int main()
{
LinkStack L;
InitLinkStack(&L);
Input(L);
return 0;
}

int pop(LinkStack L,Elemtype *e){//出栈
LinkStack s;
s=L->next;
if(s==NULL) return ERROR;
*e=s->data;
L->next=s->next;
free(s);
return TRUE;
}

int decide(LinkStack L,Elemtype a[Max]){//判断回文
int i=0;

Elemtype r;
for(i=0;i

/LinkStack r,m,r1;
Elemtype flag,a,a1;
m=r1=r=L->next;
while(r->next!=NULL) m=m->next,r=r->next->next;
r=m->next; //mz中间点
while(r->next!=NULL) r=r->next;
while(flag='1'){
pop(L,&a),a1=r->data;
if(a != a1) printf("该字符串不是回文!");return ERROR;
r1=m;
while(r1->next!=r) r1=r1->next;
r=r1;
}printf("该字符串是回文!");return TRUE;
/
}

int Input(LinkStack L)
{
Elemtype *c;
Elemtype a[Max];
c=a;
int i=0;
printf("请输入字符串;");
gets(a);

push(L,a);
decide(L,a);
return TRUE;

}

void push(LinkStack L,Elemtype a[Max]){//入栈
int i;
for(i=0;i LinkStack s;
s=(StackNode)malloc(sizeof(StackNode));
s->data=a[i]; /
printf("%c ",s->data);printf("%c ",r->data);/
s->next=L->next; /
s->next=top->next;top->next=s;*/

	L->next=s;

// } decide(L,a); //判断
}
}

/*int input(LinkStack L)
{
Elemtype a[Max];
printf("请输入字符串;");
fflush(stdin);
a=gatchar();
push(L,a);

return TRUE;

}*/

你可能感兴趣的:(学习代码5)