回文代码

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Q->rear = p;
return true;
}
bool DeQueue(LinkQueue *Q, ElemType *e) {
if (Q->front == Q->rear)
{
return false;
}
QueuePtr p = Q->front->next;
*e = p->data;
Q->front->next = p->next;
}
*(S->top++) = e;
return true;
}
bool Pop(SqStack *S, ElemType *e) {
if (S->top == S->base)
return false;
*e = (*--S->top);
return true;
}
int main () {
SqStack S;
S->base = (ElemType *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(ElemType));
if (!S->base) {
return false;
}
S->top = S->base + S->stacksize;
S->stacksize += STACKINCREMENT;
return true;
}
bool EnQueue(LinkQueue *Q, ElemType e) {
QueuePtr p = (QueuePtr)malloc(sizeof(QNode));
if (!p) {
exit(0);
}
p->data = e; p->next = NULL;
Q->rear->next = p;
Push(&S,c[i]);
EnQueue(&L,c[i]);
x++;
i++;
}
while (!(S.top == S.base)) {
Pop(&S,&b);
Βιβλιοθήκη BaiduDeQueue(&L,&a);
if (a==b) {
y++;
}
else {
break;
}
}
if (x == y) {
printf("\n是回文!\n");
if (S->base == NULL) {
return false;
}
S->top = S->base;
S->stacksize = STACK_INIT_SIZE;
return true;
}
bool Push(SqStack *S, ElemType e) {
if (S->top - S->base >= S->stacksize) {
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef char ElemType;
const int STACK_INIT_SIZE = 100;
const int STACKINCREMENT = 10;
typedef struct Node {
int stacksize;
}SqStack;
bool InitQueue(LinkQueue *Q) {
Q->front = Q->rear = (QueuePtr)malloc(sizeof (QNode));
if (!Q->front) {
exit(0); }
Q->front->next = NULL;
char data;
struct Node *next;
}QNode,*QueuePtr;
typedef struct {
QueuePtr front;
QueuePtr rear;
}LinkQueue;
typedef struct Stack {
ElemType *base;
ElemType *top;
}
else {
printf("\n不是回文!\n");
}
return 0;
}
LinkQueue L;
InitStack (&S);
InitQueue (&L);
char c[40];
ElemType a,b;
printf("输入字符,以@结尾(最大40):");
scanf("%s",c);
int i = 0;
int x = 0;
int y = 0;
while (c[i] != '@') {
if (Q->rear == p) {
Q->rear = Q->front;
}
free(p);
return true;
}
bool InitStack(SqStack *S) {
S->base = (ElemType*)malloc(STACK_INIT_SIZE*sizeof(ElemType));
相关文档
最新文档