#include <stdio.h>
#include <stdlib.h>
struct stack
{
int *data;
int capacity;
int top;
};
void Init(struct stack *p, int capacity)
{
p->top=-1;
p->capacity=capacity;
p->data=(int *)malloc(sizeof(int)*capacity);
}
int Full(const struct stack *p)
{
if(p->top == p->capacity-1)
return 1;
else
return 0;
}
int Empty(const struct stack *p)
{
if(p->top != p->capacity-1)
return 1;
else
return 0;
}
int Push(struct stack *p, int x)
{
if(Full(p))
return 0;
else{
p->data[++(p->top)] = x;
return 1;
}
}
int Pop(struct stack *p, int *px)
{
if(Empty(p))
return 0;
else{
*px = p->data[--(p->top)];
return 1;
}
}
int Top(struct stack *p, int *px)
{
*px = p->data[p->top];
return *px;
}
顺序栈的实现
最新推荐文章于 2024-08-08 17:05:23 发布