#include<iostream>
using namespace std;
struct list
{
int data; struct list *next;
};
class Stack
{
struct list *ptr;
public:
Stack()
{
ptr=NULL;
}
void push(int x)//进栈成员函数
{
struct list *newnode=new struct list;
newnode->data=x;
newnode->next=ptr;
ptr=newnode;
}
int pop()//出栈成员函数
{
//struct list *top;
int value;
value=ptr->data;
//top=ptr;
ptr=ptr->next;
//delete top;
return value;
}
int empty()
{
if(ptr==NULL)
return 1;
else
return 0;
}
};
class Queue
{
struct list *ptrf,*ptrb;
public:
Queue()
{
ptrf=ptrb=NULL;
}
void enqueue(int x)//进队成员函数
{
struct list *newnode=new struct list;
newnode->data=x;
newnode->next=NULL;
if(ptrb==NULL)
ptrf=ptrb=newnode;
else
{
ptrb->next=newnode;
ptrb=newnode;
}
}
int dequeue()//出队成员函数
{
//struct list *tmp;
int value;
value=ptrf->data;
//tmp=ptrf;
ptrf=ptrf->next;
//delete tmp;
return value;
}
};
void main()
{
Stack S;//定义一个栈对象
Queue Q;//定义一个队列对象
char ch; int e,p,d;
cout<<"输入数据:";
while((ch=getchar())!='.')
{
S.push(ch);
Q.enqueue(ch);
}
//while(!S.empty()&&S.pop()==Q.dequeue());退栈和出队,比较是否相同
e=S.empty();
while(e==0)
{
p=S.pop();
d=Q.dequeue();
if(p!=d)
break;
}
if(e==1)
cout<<"输入的是回文数据."<<endl;
else
cout<<"输入的不是回文数据."<<endl;
system("pause");
}