判断回文

来源:互联网 发布:多线程和并发编程 编辑:程序博客网 时间:2024/05/16 10:44

回文是指正读反读均相同的字符序列,如“abba”,和“abdba”均是回文,但“good”不是回文,试写一个算法判定给定的字符向量是否为回文。(提示:将一半字符入栈)

 

 

// e1.cpp : Defines the entry point for the console application.

//

 

#include "stdafx.h"

 

#include "stdio.h"

 

define StackSize 100 

typedef char DataType ;

typedef Struct {

DataType data [StackSize] ;

int top ;

} SeqStack ;

int ISHuiWen (char *t)

{//判断t字符向量是否是回文,若是,返1,否则返回0 

SeqStack s;

int i,len ;

char temp ;

InitStack(&s);

len<strlen(t);

for(i=0;i<len/2;i++)

push (&s,t[i]) ;

while (!EmptyStack(&s))

{temp=pop(&s);

if(temp!=s[i])

return 0;

else i++

}

return 1;

}

原创粉丝点击