#include<iostream>
#include<cstring>
//#define StackMax 100
using namespace std;
typedef struct LinkQueue
{
struct LinkQueue *next;
string data;
}LinkQueue,*LinkStack;
typedef struct Queue
{
LinkQueue *front;
LinkQueue *rear;
}Queue;
void Stack(Queue &Q,LinkStack &S)//初始化栈和队
{
Q.front=Q.rear=new LinkQueue;
Q.front->next=NULL;
S=NULL;
}
void push(Queue &Q,LinkStack &S)//Q入队,S入栈
{
string a;
bool flag1=true;
LinkQueue *p;
p=new LinkQueue;
int b;
while(flag1)//队的输入
{
cout<<"1:继续输入 2:结束输入"<<endl;
cin>>b;
switch(b)
{
case 1:
cout<<"请在系统中挨个输入你要的内容"<<endl;
cin>>a;
p=new LinkQueue;
p->data=a;
p->next=NULL;
Q.rear->next=p;
Q.rear=p;
break;
case 2:
flag1=false;
}
}
cout<<"请按照原文再输入一遍"<<endl;
bool flag2=true;
while(flag2)//栈的输入
{
cout<<"1:继续输入 2:结束输入"<<endl;
cin>>b;
switch(b)
{
case 1:
LinkQueue *q;
q=new LinkQueue;
cout<<"请输入需要的数据"<<endl;
cin>>a;
q->data=a;
q->next=S;
S=q;
break;
case 2:
flag2=false;
}
}
}
void pop(Queue Q,LinkStack S)
{
cout<<"测试"<<endl;
int i=0;
string t[1000];
LinkStack p;
printf("链式队列中的元素");
if(Q.front->next!=NULL)
{
cout<<"测试"<<endl;
p=Q.front->next;
do
{
t[i]=p->data;
i++;
p=p->next;
}while(p!=NULL);
}
else
printf("队列为空\n");
printf("\n");
//栈遍历
int f=0;
string d[1000];
LinkStack *q=new LinkStack;
if(q!=NULL)
{
while(q!=NULL)
{
d[1000]=p->data;
f++;
}
}
while(f!=0)
{
if(d[f]!=t[i])
{
break;
}
i--;
f--;
}
if(f==0)
{
cout<<"是回文数"<<endl;
}
else
{
cout<<"不是回文数"<<endl;
}
}
int main()
{
LinkStack S;
Queue Q;
Stack(Q,S);
push(Q,S);
pop(Q,S);
}
运行pop函数时出现错误