编程序判断一个字符序列是否是回文,要求同时采用队列和堆栈,数据结构程序没有错误,为什么运行不了?
#include<stdio.h>#include<string.h>#include<stdlib.h#include<malloc.h>#defineMaxStack...
#include<stdio.h>
#include<string.h>
#include<stdlib.h
#include<malloc.h>
#define MaxStackSize 100
#define MaxQueueSize 100
typedef char ElemType;
typedef struct
{
ElemType *stack;
int top;
}SequenceStack;
typedef char DataType;
typedef struct
{
DataType queue[MaxQueueSize];
int rear;
int front;
} SequenceQueue;
#include "SeqStack.h"
#include "SeqCQueue.h"
void main()
{
SeqStack st;
SeqCQueue Q;
int i,flag;
flag=1;
char str[10],y,z;
printf("输入一串字符:");
gets(str);
for(i=0;(size_t)i<strlen(str);i++)
{
StackPush(&st,str[i]);
QueueAppend(&Q,str[i]);
}
while(StackNotEmpty(st)&&QueueNotEmpty(Q))
{
StackPop(&st,&y);
QueueDelete(&Q,&z);
if(y!=z)
{
flag=0; break;
}
if(flag==1)
printf("该字符串是回文!\n");
else printf("该字符串不是回文!\n");
} 展开
#include<string.h>
#include<stdlib.h
#include<malloc.h>
#define MaxStackSize 100
#define MaxQueueSize 100
typedef char ElemType;
typedef struct
{
ElemType *stack;
int top;
}SequenceStack;
typedef char DataType;
typedef struct
{
DataType queue[MaxQueueSize];
int rear;
int front;
} SequenceQueue;
#include "SeqStack.h"
#include "SeqCQueue.h"
void main()
{
SeqStack st;
SeqCQueue Q;
int i,flag;
flag=1;
char str[10],y,z;
printf("输入一串字符:");
gets(str);
for(i=0;(size_t)i<strlen(str);i++)
{
StackPush(&st,str[i]);
QueueAppend(&Q,str[i]);
}
while(StackNotEmpty(st)&&QueueNotEmpty(Q))
{
StackPop(&st,&y);
QueueDelete(&Q,&z);
if(y!=z)
{
flag=0; break;
}
if(flag==1)
printf("该字符串是回文!\n");
else printf("该字符串不是回文!\n");
} 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励20(财富值+成长值)+提问者悬赏5(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询