判断回文

xiaoxiao2021-03-01  41

回文是指正读反读均相同的字符序列,如“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;

}

转载请注明原文地址: https://www.6miu.com/read-3200120.html

最新回复(0)