📄 station.h
字号:
//顺序栈实现
#include<iostream.h>
class AStack{
private:
int size;
int top;
char *listArray;
public:
AStack(int sz=0)
{
size=sz;
top=0;
listArray=new char(sz);
}
//~AStack(){delete []listArray;};
void clear() ;
bool push( char& item);
bool pop(char &it);
bool topValue(char &it) const;
bool isEmpty();
void print();
int length() const;
};
void AStack::clear() {top=0; }
bool AStack::push( char& item)
{
if(top==size)
return false;
else
{
listArray[top++]=item;
return true;
}
}
bool AStack::pop(char &it)
{
if(top==0)
return false;
else
{
it=listArray[--top];
return true;
}
}
bool AStack::topValue(char &it) const
{
if(top==0)
return false;
else
{
it=listArray[top-1];
return true;
}
}
bool AStack::isEmpty()
{
if(top==0)
return true;
else
return false;
}
void AStack::print()
{
if(top==0)
cout<<"\nThe stack is empty!";
else
for(int i=0;i<top;i++)
cout<<listArray[i]<<" ";
cout<<endl;
}
int AStack::length() const
{
return top;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -