#include <stdio.h>
#define MAXSIZE 30
#define OK 1
#define ERROR 0
typedef int ElemType;
typedef int Status;
typedef struct SqStack
{
ElemType data[MAXSIZE];
int top;
}Stack;
void IintStack(Stack *s)
{
s->top = -1;
printf("顺序栈初始化为空!\n");
}
void DestoryStack(Stack *s)
{
s->top = -1;
printf("顺序栈销毁为空\n");
}
void print(const Stack *s)
{
if (s->top == -1)
{
printf("当前栈为空!\n");
return ;
}
int i;
for ( i = s->top; i >= 0; i--)
{
printf("%d ",s->data[i]);
}
printf("\n");
}
Status Push(Stack *s,ElemType e)
{
if (s->top == MAXSIZE - 1)
{
printf("当前栈已满,无法入栈!\n");
return ERROR;
}
s->top++;
s->data[s->top] = e;
return OK;
}
Status Pop(Stack *s,ElemType *e)
{
if (s->top == -1)
{
printf("当前栈为空,无法弹出\n");
return ERROR;
}
*e = s->data[s->top];
s->top--;
return OK;
}
int main()
{
Stack s1;
IintStack(&s1);
int i,e;
for ( i = 1; i <= 9; ++i)
{
Push(&s1,i);
}
print(&s1);
Pop(&s1,&e);
print(&s1);
return 0;
}
#define MAXSIZE 30
#define OK 1
#define ERROR 0
typedef int ElemType;
typedef int Status;
typedef struct SqStack
{
ElemType data[MAXSIZE];
int top;
}Stack;
void IintStack(Stack *s)
{
s->top = -1;
printf("顺序栈初始化为空!\n");
}
void DestoryStack(Stack *s)
{
s->top = -1;
printf("顺序栈销毁为空\n");
}
void print(const Stack *s)
{
if (s->top == -1)
{
printf("当前栈为空!\n");
return ;
}
int i;
for ( i = s->top; i >= 0; i--)
{
printf("%d ",s->data[i]);
}
printf("\n");
}
Status Push(Stack *s,ElemType e)
{
if (s->top == MAXSIZE - 1)
{
printf("当前栈已满,无法入栈!\n");
return ERROR;
}
s->top++;
s->data[s->top] = e;
return OK;
}
Status Pop(Stack *s,ElemType *e)
{
if (s->top == -1)
{
printf("当前栈为空,无法弹出\n");
return ERROR;
}
*e = s->data[s->top];
s->top--;
return OK;
}
int main()
{
Stack s1;
IintStack(&s1);
int i,e;
for ( i = 1; i <= 9; ++i)
{
Push(&s1,i);
}
print(&s1);
Pop(&s1,&e);
print(&s1);
return 0;
}