#include
#include
#define SIZE 100
typedef struct __Stack
{
int *data;
int pos;
}Stack;
int Stack_Initial(Stack *stack)
{
stack->data = (int*) malloc(sizeof(int));
if(stack->data == NULL) return 0;
stack->pos = -1;
}
int Stack_Push(Stack *stack,int value)
{
if(stack->pos == (SIZE-1) )
{
printf("栈已满\n");
return 0;
}
stack->pos++;
stack->data[stack->pos] = value;
return 1;
}
int Stack_Pop(Stack *stack)
{
if(stack->pos == -1) return 0;
stack->pos--;
return 1;
}
int Stack_GetTop(Stack *stack)
{
if(stack->pos == -1)
{
printf("栈为空\n");
return 0;
}
return stack->data[stack->pos];
}
void Stack_Show(Stack *stack)
{
if(stack->pos == -1)
{
printf("栈为空\n");
return;
}
for(int i = 0; i <= stack->pos;i++)
{
printf("%10d",stack->data[i]);
}
}
void Stack_Destroy(Stack *stack)
{
free(stack->data);
}