栈
顺序栈
#ifndef __SEQSTACK_H__
#define __SEQSTACK_H__
#define MAXSIZE 100
typedef int datatype;
typedef struct
{
datatype data[MAXSIZE];
int top;
}SeqStack;
SeqStack* Init_SeqStack();
int Empty_SeqStack(SeqStack* s);
void Push_SeqStack(SeqStack* s, datatype x);
void Pop_SeqStack(SeqStack*, datatype* x);
void Top_SeqStack(SeqStack* s, datatype *x);
#endif
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include"SeqStack.h"
SeqStack* Init_SeqStack()
{
SeqStack* seq = (SeqStack*)malloc(sizeof(SeqStack));
seq->top = -1;
return seq;
}
int Empty_SeqStack(SeqStack* s)
{
return s->top == -1 ? 1 : 0;
}
void Push_SeqStack(SeqStack* s, datatype x)
{
if (s->top == MAXSIZE - 1)
{
printf("Stack is Full\n");
}
else
{
s->top++;
s->data[s->top] = x;
}
}
void Pop_SeqStack(SeqStack* s, datatype* x)
{
if (Empty_SeqStack(s))
{
printf("Stack is empty!\n");
}
else
{
*x = s->data[s->top];
s->top--;
}
}
void Top_SeqStack(SeqStack* s, datatype* x)
{
if (Empty_SeqStack(s))
{
printf("Stack is empty!\n");
}
else
{
*x = s->data[s->top];
}
}
回文序列

int is_palindrome(char str[])
{
SeqStack* seq = Init_SeqStack();
Push_SeqStack(seq, '\0');
char* p = str;
while (*p != '\0')
{
Push_SeqStack(seq,*p);
p