#include<iostream.h>
const int StackSize=25;
class SeqStack
{
public:
SeqStack(){top=-1;}
~SeqStack(){}
void Push(int x);
int Pop();
int GetTop();
private:
int data[StackSize];
int top;
};
void SeqStack::Push(int x)
{
if(top==StackSize-1)throw"上溢";
data[++top]=x;
}
int SeqStack::Pop()
{
int x;
if(top==-1)throw"下溢";
x=data[top--];
return x;
}
int SeqStack::GetTop()
{
if(top!=-1)
return data[top];
}
int main()
{
SeqStack s;
s.Push(5);
s.Push(10);
cout<<"顶端元素为:"<<s.GetTop()<<endl;
cout<<"执行一次Pop操作"<<endl;
s.Pop();
cout<<"顶端元素为:"<<s.GetTop()<<endl;
}
const int StackSize=25;
class SeqStack
{
public:
SeqStack(){top=-1;}
~SeqStack(){}
void Push(int x);
int Pop();
int GetTop();
private:
int data[StackSize];
int top;
};
void SeqStack::Push(int x)
{
if(top==StackSize-1)throw"上溢";
data[++top]=x;
}
int SeqStack::Pop()
{
int x;
if(top==-1)throw"下溢";
x=data[top--];
return x;
}
int SeqStack::GetTop()
{
if(top!=-1)
return data[top];
}
int main()
{
SeqStack s;
s.Push(5);
s.Push(10);
cout<<"顶端元素为:"<<s.GetTop()<<endl;
cout<<"执行一次Pop操作"<<endl;
s.Pop();
cout<<"顶端元素为:"<<s.GetTop()<<endl;
}