1.mian.cpp文件内容:
#include <iostream>
#include <stdlib.h>
#include "GlobalDefine.h"
#include "LinkList.h"
#include "Stack.h"
using namespace std;
int main()
{
//Page85.2.(3)
int input_num, pop_num;
SqStack s;
cout<<"\n输入整数序列:";
Init_Stack(s);
do
{
cin>>input_num;
if(input_num == -1)
{
if(Pop_Stack(s, pop_num))
{
cout<<pop_num;
}
}
else
{
Push_Stack(s, input_num);
}
}while(s.top - s.base <= s.stacksize);
system("PAUSE");
}
2.Stack.cpp文件中相关内容:
typedef int Status;
const int TRUE = 1;
const int FALSE = 0;
const int STACK_MAXSIZE = 5;
Status Push_Stack(SqStack &s, StackElementType &e)
{
if(s.top - s.base == s.stacksize)
{
cout<<"\nerror:栈满";
return FALSE;
}
else
{
*s.top = e;
s.top ++;
}
return TRU