利用栈和循环队列判断回文
来源:互联网 发布:科立捷对讲机端口是几 编辑:程序博客网 时间:2024/04/28 01:41
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAXSIZE 40
typedef struct{
char *base;
int frone;
int rear;
}user_queue;
typedef struct{
char *base;
char *top;
}user_stack;
user_queue *reword;
user_stack *c_stack;
//--------------------------------------------------
int EnQueue(user_queue *reword,char e){
if((reword->rear+1)%MAXSIZE==reword->frone) return 0;
reword->base[reword->rear]=e;
reword->rear=(reword->rear+1)%MAXSIZE;
return 1;
}//-----------------------------------------------------
int DeQueue(user_queue *reword,char *e){
if(reword->frone==reword->rear) return 0;
*e=reword->base[reword->frone];
reword->frone=(reword->frone+1)%MAXSIZE;
return 0;
}//--------------------------------------------------------
int queuelen(user_queue *reword){
return (reword->rear-reword->frone+MAXSIZE)%MAXSIZE;
}//--------------------------------------------------------
int push(user_stack *c_stack,char e){
*(c_stack->top)=e;
(c_stack->top)++;
return 1;
}//-----------------------------------------------------------
int pop(user_stack *c_stack,char *e){
(c_stack->top)--;
*e=*(c_stack->top);
return 0;
}//---------------------------------------------------------
int main(){
char e,a,b;
int L,i;
reword=(user_queue *)malloc(sizeof(user_queue));
reword->base=(char *)malloc(MAXSIZE*sizeof(char));
reword->frone=reword->rear=0;
c_stack=(user_stack *)malloc(sizeof(user_stack));
c_stack->base=(char *)malloc(MAXSIZE/2*sizeof(char));
c_stack->top=c_stack->base;
printf("please input char,end('#'):/n");
e=getchar();
while(e!='#'){
EnQueue(reword,e);
e=getchar();
}
L=queuelen(reword);
for(i=0;i<L/2;i++){
DeQueue(reword,&e);
push(c_stack,e);
}
if(L%2!=0) DeQueue(reword,&e);
for(i=0;i<L/2;i++){
DeQueue(reword,&a);
pop(c_stack,&b);
if(a!=b){
printf("the string is NOT back_word./n");
return 0;
}
}
printf("the string is back_word./n");
return 1;
}//==========================================================
- 利用栈和循环队列判断回文
- 数据结构之栈和队列---回文判断
- 用栈和队列实现回文判断
- 栈和队列判断回文数
- 栈和队列判断回文数
- 用数据结构的栈和队列 写 回文判断
- 数据结构 用栈和队列判断回文数
- 用栈和队列实现判断是否回文
- 【数据结构】使用栈和队列判断字符串是否是回文
- 回文(栈和队列)
- 利用栈判断回文数。
- 【数据结构】队列+栈 判断回文数
- 只用栈与队列实现判断回文
- 使用栈与队列判断回文串
- 利用顺序栈判断字符串是否回文
- 判断循环队列满
- 用队列和栈实现回文
- 用栈和队列实现回文
- 用Java实现二叉树
- 最新版飞鸽传书下载
- jndi
- 各大调音阶之间的对应关系
- 集合 List ArrayList 问题
- 利用栈和循环队列判断回文
- 灰度图像淡入到彩色图像与彩色图像淡出到灰度图像
- 决策树的构造——一个手工例子
- HR相关表
- VC++深入详解 孙鑫作品系列
- webclient实现多图片上传
- NHibernate教程
- 尘埃落定,长出一口气。。。。
- DBGridEH 详细参数