- #include<iostream.h>
- #include<string.h>
- struct sqstack
- {
- char data;
- sqstack* top;
- };
- class stack
- {
- sqstack * st;
- public:
- void init()
- {
- st=NULL;
- }
- void push(char );
- char pop();
- };
- void stack::push(char k)
- {
- sqstack * newst=new sqstack;
- newst->data=k;
- newst->top=st;
- st=newst;
- }
- char stack::pop()
- {
- char value;
- sqstack* t;
- value=st->data;
- t=st;
- st=st->top;
- delete t;
- return value;
- }
- struct list
- {
- int data;
- list *next;
- };
- class queue
- {
- list *head,*tail;
- public:
- void init()
- {
- head=tail=NULL;
- }
- void Inq(int x);
- int Outq();
- };
- void queue::Inq(int x)
- {
- list *newnd=new list;
- newnd->data=x;
- newnd->next=NULL;
- if(tail==NULL)
- head=tail=newnd;
- else
- {
- tail->next=newnd;
- tail=newnd;
- }
- }
- int queue::Outq()
- {
- list *temp;
- int value;
- value=head->data;
- temp=head;
- head=head->next;
- delete temp;
- return value;
- }
- void main()
- {
- stack A;
- A.init();
- queue B;
- B.init();
- char arr[80];
- cout<<"请输入字符序列,回车键结束:"<<endl;
- cin.getline(arr,80);
- int h=strlen(arr);
- for (int i=0;i<h;i++)
- {
- A.push(arr[i]);
- B.Inq(arr[i]);
- }
- for(i=0;i<h;i++)
- {
- if(A.pop()!=B.Outq())
- {
- cout<<"你所输入的字符序列不是回文!"<<endl;
- return;
- }
- }
- cout<<"你所输入的字符序列是回文!"<<endl;
- }