#include <iostream>
using namespace std;
#define MAXSIZE 1024
typedef int MyType;
typedef struct
{
MyType data[MAXSIZE];
int top;
}SeqStack;
SeqStack *Init_SeqStack()
{
SeqStack *s;
s = (SeqStack*)malloc(sizeof(SeqStack));
s->top= -1;
return s;
}
bool Empty_SeqStack(SeqStack *s)
{
if (s->top == -1)
return 1;//true
else
return 0;//false
}
bool Push_SeqStack (SeqStack *s, MyType x)
{
if (s->top == MAXSIZE-1)
return 0;//false
else {
s->top++;
s->data[s->top] = x;
return 1;//true
}
}
bool Pop_SeqStack(SeqStack *s, MyType *x)
{
if (Empty_SeqStack(s))
return 0;//false
else
{
*x=s->data[s->top];
s->top--;
return 1;//true
}
}
MyType Top_SeqStack(SeqStack *s)
{
if ( Empty_SeqStack(s))
return NULL;
else
return (s->data[s->top] );
}
int main()
{
SeqStack *MyStack;
MyStack = Init_SeqStack();
MyType value;
for (int i=0; i<10; ++i){
Push_SeqStack(MyStack,i);
cout<<Top_SeqStack(MyStack)<<' ';
}
cout<<endl;
for (i=0; i<20;++i){
if(!Empty_SeqStack(MyStack)) {
cout<<Top_SeqStack(MyStack)<<' ';
Pop_SeqStack(MyStack, &value);
}
}
cout<<endl;
return 0;
}