#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 10
typedef int DataType;
typedef struct
{
DataType data[MAX_SIZE];
int top;
} SeqStack;
void Initial(SeqStack* s);
void push(SeqStack* s, DataType x);
DataType pull(SeqStack* s);
void print(SeqStack* s);
int main()
{
SeqStack s;
Initial(&s);
for (int i = 0; i < 4; i++)
{
push(&s, i);
}
DataType x;
for (int i = 0; i < 4; i++)
{
x = pull(&s);
printf("%d", x);
}
system("pause");
return 0;
}
void Initial(SeqStack* s)
{
s->top = -1;
}
void push(SeqStack* s, DataType x)
{
if (s->top == MAX_SIZE - 1)
{
printf("%d", x);
printf("元素已满!");
}
else
{
s->data[++s->top] = x;
}
}
DataType pull(SeqStack* s)
{
DataType x;
if (s->top == -1)
{
printf("栈内元素为控空,无法遍历!");
}
else
{
x = s->data[s->top--];
}
return x;
}
void print(SeqStack* s)
{
if (s->top == -1)
{
printf("元素为空!无法遍历。");
}
else
{
while (s->top != -1)
{
printf("%d", s->data[s->top--]);
}
}
return;
}