主题:求救,用栈和队列进行回文判断,有好多错误,谁帮忙看一下
#include<stdio.h>
#define ok 1
#define error 0
#define stack_size 50
typedef struct //定义顺序栈
{ char elem[stack_size];
int top;
}seqstack;
typedef struct node //定义链队列
{ char date;
struct node *next;
}linkqueuenode;
typedef struct
{ linkqueuenode *front;
linkqueuenode *rear;
}linkqueue;
void initstack(seqstack *s) //初始化顺序栈
{ s->top=-1;
}
void push(seqstack *s,char x) //进栈
{ if(s->top==stack_size-1)
printf("栈已满");
else
{
s->top++;
s->elem[s->top]=x;
}
}
void pop(seqstack *s,char*x) //出栈
{ if(s->top==-1)
printf("栈为空");
else
{ *x=s->elem[s->top];
s->top--;
}
}
void initqueue(linkqueue *q) //初始化队列
{ q->front=(linkqueuenode *)malloc(sizeof(linkqueuenode));
if(q->front!=null)
{ q->rear=q->front;
q->front->next=null;
}
else
printf("链队列溢出");
}
void enterqueue(linkqueue * q,char x) //入队
{ linkqueuenode * s;
s=(linlqueuenode*)malloc(sizeof(linlqueuenode));
if(s!=null)
{ s->date=x;
s->next=null;
q->rear->next=s;
q->rear=s;
}
else
printf("链队列溢出");
}
void deletequeue(linkqueue *q,char *x) //出队
{ linkqueue *p;
if(q->front==q->rear)
printf("对为空");
p=q->front->next;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
*x=p->date;
//free(p);
}
void main()
{ seqstack l;
linkqueue y;
char ch1,ch2,ch;
int m=0,i;
initstack(&l);
initqueue(&y);
printf("请输入一串字符(以@结尾):");
ch=getchar();
while(ch!='@')
{ ch=getchar();
if(ch!='@')
{push(&l,ch);
enterqueue(&y,ch);
m++;
}
}
if(m%2!=0)
{
if(l->elem[m/2]=='&')
{
for(i=1;i<m/2;i++)
{ pop(&l,&ch1);
deletequeue(&y,&ch2);
if(ch1!=ch2)
printf("不是回文序列");
else
printf("不是回文序列");
}
}
else
printf("不是回文序列");
}
}
#define ok 1
#define error 0
#define stack_size 50
typedef struct //定义顺序栈
{ char elem[stack_size];
int top;
}seqstack;
typedef struct node //定义链队列
{ char date;
struct node *next;
}linkqueuenode;
typedef struct
{ linkqueuenode *front;
linkqueuenode *rear;
}linkqueue;
void initstack(seqstack *s) //初始化顺序栈
{ s->top=-1;
}
void push(seqstack *s,char x) //进栈
{ if(s->top==stack_size-1)
printf("栈已满");
else
{
s->top++;
s->elem[s->top]=x;
}
}
void pop(seqstack *s,char*x) //出栈
{ if(s->top==-1)
printf("栈为空");
else
{ *x=s->elem[s->top];
s->top--;
}
}
void initqueue(linkqueue *q) //初始化队列
{ q->front=(linkqueuenode *)malloc(sizeof(linkqueuenode));
if(q->front!=null)
{ q->rear=q->front;
q->front->next=null;
}
else
printf("链队列溢出");
}
void enterqueue(linkqueue * q,char x) //入队
{ linkqueuenode * s;
s=(linlqueuenode*)malloc(sizeof(linlqueuenode));
if(s!=null)
{ s->date=x;
s->next=null;
q->rear->next=s;
q->rear=s;
}
else
printf("链队列溢出");
}
void deletequeue(linkqueue *q,char *x) //出队
{ linkqueue *p;
if(q->front==q->rear)
printf("对为空");
p=q->front->next;
q->front->next=p->next;
if(q->rear==p)
q->rear=q->front;
*x=p->date;
//free(p);
}
void main()
{ seqstack l;
linkqueue y;
char ch1,ch2,ch;
int m=0,i;
initstack(&l);
initqueue(&y);
printf("请输入一串字符(以@结尾):");
ch=getchar();
while(ch!='@')
{ ch=getchar();
if(ch!='@')
{push(&l,ch);
enterqueue(&y,ch);
m++;
}
}
if(m%2!=0)
{
if(l->elem[m/2]=='&')
{
for(i=1;i<m/2;i++)
{ pop(&l,&ch1);
deletequeue(&y,&ch2);
if(ch1!=ch2)
printf("不是回文序列");
else
printf("不是回文序列");
}
}
else
printf("不是回文序列");
}
}