access中判断回文的代码_判断是否回文字符串
发布日期:2021-10-31 12:51:51 浏览次数:3 分类:技术文章

本文共 1667 字,大约阅读时间需要 5 分钟。

#include

#define m 100

/* 定义栈*/

typedef struct {

char stack[m];

int  top;

}stackstru;

/*初始化栈*/

int stinit(stackstru *s)

{

s->top=0;

return 1;

}

/*判断栈是否空*/

int stempty(stackstru *s)

{

if(s->top==0)

{

return 0;

}

else

{

return 1;

}

}

/*入栈操作*/

int stpush(stackstru *s,char x)

{

if(s->top==m)

{

printf("The stack is overflow!\n");

return 0;

}

else

{

s->top=s->top+1;

s->stack[s->top]=x;

return 1;

}

}

/*出栈操作*/

char stpop(stackstru *s)

{

char y;

if(s->top==0)

{

printf("The stack is empty!\n");

return '';

}

else

{

y=s->stack[s->top];

s->top=s->top-1;

return y;

}

}

/*定义队列*/

typedef struct {

char queue[m];

int  front;

int  rear;

}queuestru;

/*初始化队列*/

int quinit(queuestru *q)

{

q->front=0;

q->rear=0;

return 1;

}

/*判断队列是否为空*/

int quempty(queuestru *q)

{

if(q->front==q->rear)

{

return 0;

}

else

{

return 1;

}

}

/*入队操作*/

int enqueue(queuestru *q,char e)

{

if((q->rear+1)%m==q->front)

{

printf("The queue is overflow!\n");

return 0;

}

else

{

q->queue[q->rear]=e;

q->rear=(q->rear+1)%m;

return 1;

}

}

/*出队操作*/

char dequeue(queuestru *q)

{

char f;

if(q->front==q->rear)

{

printf("The queue is empty!\n");

return 0;

}

else

{

f=q->queue[q->front];

q->front=(q->front+1)%m;

return f;

}

}

/*主程序*/

main()

{

char c;

int v;

stackstru *s=(stackstru *)malloc(sizeof(stackstru));

stackstru *q=(stackstru *)malloc(sizeof(queuestru));

stinit(s);

quinit(q);

printf("Input a string:\n");//输入字符串,输入@标示输入结束。

while((c=getchar())!='@')

{

putchar(c);

stpush(s,c);

enqueue(q,c);

}

printf("End input!\n");

while(stempty(s))

{

if(stpop(s)==dequeue(q))

{

v=1;

continue;

}

else

{

v=0;

break;

}

}

if(v==1)

{

printf("This string is palindrome!\n");

}

else

{

printf("This string isn't palindrome!\n");

}

}

转载地址:https://blog.csdn.net/weixin_39965881/article/details/111778317 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:不能用了 重装系统git_win10 重装系统后从0搭建java环境及git环境
下一篇:koa 接口返回数据_node+koa实现数据mock接口的方法

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2024年04月21日 00时48分31秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章