#include <iostream>
#define MAXSIZE 1024
#define null 0
using namespace std;
typedef char DataType; //顺序栈的类型描述
typedef struct{
DataType data[MAXSIZE];
int top;
}SeqStack;
//顺序栈的初始化算法
SeqStack *init_SeqStack(){
SeqStack *s;
s=new SeqStack;
if(!s)
{
cout<<"空间不足"<<endl;
return NULL;
}
else
{
s->top=-1;
return s;
}
}
//栈空判断算法/
int Empty_SeqStack(SeqStack *s){
if(s->top==-1)
return 1;
else return 0;
}
//入栈算法
int push_SeqStack(SeqStack *s,DataType x){
if(s->top==MAXSIZE-1) return 0; //栈满不能入栈
else {
s->top++;
s->data[s->top]=x;
return 1;
}
}
//出栈算法
int Pop_SeqStack(SeqStack *s,DataType *x){
if(Empty_SeqStack(s)) //栈空不能出栈
return 0;
else{
*x=s->data[s->top];
s->top--;
return 1;
} //栈顶元素存入*x,返回
}
//取栈顶元素
DataType Top_SeqStack(SeqStack *s){
if(Empty_SeqStack(s))
return null;
else
return s->data[s->top];
}
//判断回文
int main(){
SeqStack *p;
DataType q,m;
DataType d;
p=init_SeqStack();
cout<<"请输入一串字符序列数"<<endl;
cin>>q;
while(q!='@'){
push_SeqStack(p,q);
cin>>q;
}
cout<<"p="<<p->data[p->top];
d=huiwen(p);
if(d==1) cout<<"此字符串是回文。/n"<<d;
else cout<<"此字符串不是回文。/n";
cout<<"/n<-------------------安云飞所做------------------------>"<<endl;
return 0;
}
5342

被折叠的 条评论
为什么被折叠?



