#include <iostream>
#include <stdlib.h>
#include <string.h>
const int maxsize=20;
using namespace std;
class Stack{
private:
char *s;
int top;
int capacity;
public:
Stack()
{
s=new char[maxsize];
top=0;
}
Stack(int capacity)
{
this->capacity=capacity;
}
~Stack()
{
delete[]s;
}
void push(char e)
{
if(top>maxsize-1)
{
cout<<"overflow!"<<endl;
exit(0);
}
else
s[top++]=e;
}
int pop()
{
return s[--top];
}
bool isEmpty()
{
if(top==0)
return true;
else
return false;
}
};
bool isPalindrome(char *s)
{
Stack mystack;
int index=0;
int len=strlen(s);
for(int i=0;i<len/2;i++)
{
mystack.push(s[index++]);
}
if(len%2==1)
index++;
bool flag=true;
wh
C++ 用出入栈判断字符串是否为回文
最新推荐文章于 2025-06-23 19:56:46 发布