```c
#ifndef _STACK_H_
#define _STACK_H_
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
typedef int datatype;
typedef struct {
datatype *data;
int maxlen;
int top;
}sqstack;
extern sqstack * CreateStack(int len);
extern int EmptyStack(sqstack *s);
extern int FullStack(sqstack *s);
extern void ClearStack(sqstack *s);
extern int PushStack(sqstack *s,datatype data);
extern int PopStack(sqstack *s);
extern datatype TopStack(sqstack *s);
extern void DeleteStack(sqstack *s);
extern void ShowStack(sqstack *s);
#endif
#include"stack.h"
sqstack * CreateStack(int len)
{
sqstack *s = NULL;
if((s = (sqstack *)malloc(sizeof(sqstack))) ==NULL)
{
printf("malloc fail\n");
return NULL;
}
if((s->data = (datatype *)malloc(sizeof(datatype) * len)) == NULL)
{
printf("malloc fail\n");
return NULL;
}
s->maxlen = len ;
s->top = -1;
return s;
}
int EmptyStack(sqstack *s)
{
return (s->top == -1? 1:0) ;
}
int FullStack(sqstack *s)
{
return ((s->top == s->maxlen-1) ? 1:0);
}
void ClearStack(sqstack *s)
{
s->top = -1;
}
int PushStack(sqstack *s,datatype data)
{
if(FullStack(s))
{
printf("满栈\n");
return 0;
}
s->top = s->top+1;
s->data[s->top] = data;
return 1;
}
int PopStack(sqstack *s)
{
if(EmptyStack(s))
{
printf("空栈\n");
return 0;
}
s->top = s->top-1;
return (s->data[s->top+1]);
}
datatype TopStack(sqstack *s)
{
return s->top;
}
void DeleteStack(sqstack *s)
{
free(s);
s = NULL;
}
void ShowStack(sqstack *s)
{
if(EmptyStack(s))
{
printf("空栈\n");
return ;
}
int i ;
for(i = 0 ;i<= s->top;i++)
printf("%3d",s->data[i]);
putchar(10);
}
```c
#ifndef _STACK_H_
#define _STACK_H_
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
typedef int datatype;
typedef struct sqst{
datatype data;
struct sqst* next;
}sqstack;
extern sqstack * CreateStack();
extern int EmptyStack(sqstack *s);
extern int PushStack(sqstack *s,datatype data);
extern int PopStack(sqstack *s,int *D);
extern datatype TopStack(sqstack *s);
extern void DeleteStack(sqstack *s);
extern void ShowStack(sqstack *s);
#endif
#include"stack.h"
sqstack * CreateStack()
{
sqstack *s = NULL;
if((s = (sqstack *)malloc(sizeof(sqstack))) ==NULL)
{
printf("malloc fail\n");
return NULL;
}
s->next = NULL;
return s;
}
int EmptyStack(sqstack *s)
{
return (s->next == NULL? 1:0) ;
}
void DeleteStack(sqstack *s)
{
sqstack *p = s->next ;
while(p)
{
s->next = p->next;
free(p);
p = s->next;
}
if(s->next == NULL)
{
free(s);
printf("delete success\n");
}
}
int PushStack(sqstack *s,datatype data)
{
sqstack *new = (sqstack*)malloc(sizeof(sqstack));
new->next = NULL;
new->data = data;
new->next = s->next;
s->next = new;
return 1;
}
int PopStack(sqstack *s,datatype *D)
{
if(EmptyStack(s))
{
printf("空栈\n");
return 0;
}
sqstack *q;
q = s->next;
*D = q->data;
s->next = q->next;
free(q);
q= NULL;
return 1;
}
void ShowStack(sqstack *s)
{
if (EmptyStack(s))
{
printf("empty\n");
}
sqstack *q = s->next;
while(q)
{
printf("%5d",q->data);
q = q->next;
}
putchar(10);
}