Stack.h:定义了基本操作
#include "Stack.h"
using namespace std;
void print(int e)
{
cout<<e<<" ";
}
int main()
{
int i,tmp;
Stack S;
InitStack(S);
for(i=1;i<=5;i++)
if(Push(S,i)==OK)
cout<<i<<"入栈"<<" ";
cout<<endl;
StackTraverse(S,print);
cout<<endl;
Pop(S,tmp);
cout<<tmp<<"出栈"<<endl;
StackTraverse(S,print);
cout<<endl<<"当前栈的大小"<<GetLen(S)<<endl;
cout<<"清空栈";
ClearStack(S);
cout<<endl<<"当前栈的大小"<<GetLen(S)<<endl;
return 0;
}
#include "Stack.h"
using namespace std;
void print(int e)
{
cout<<e<<" ";
}
main.cpp:主程序
int main()
{
int i,tmp;
Stack S;
InitStack(S);
for(i=1;i<=5;i++)
if(Push(S,i)==OK)
cout<<i<<"入栈"<<" ";
cout<<endl;
StackTraverse(S,print);
cout<<endl;
Pop(S,tmp);
cout<<tmp<<"出栈"<<endl;
StackTraverse(S,print);
cout<<endl<<"当前栈的大小"<<GetLen(S)<<endl;
cout<<"清空栈";
ClearStack(S);
cout<<endl<<"当前栈的大小"<<GetLen(S)<<endl;
return 0;
}