📄 astack.h
字号:
#define DefaultListSize 20
// below is astack implementation;
template <class Elem> class AStack{
private:
int size;
int top;
Elem *listArray;
public:
AStack(int sz =DefaultListSize)
{ size = sz; top = 0; listArray = new Elem[sz]; }
~AStack() { delete [] listArray; }
void clear() { top = 0; }
bool push(const Elem& item) {
if (top == size) return false;
else { listArray[top++] = item; return true; }
}
bool pop(Elem& it) {
if (top == 0) return false;
else { it = listArray[--top]; return true; }
}
bool topValue(Elem& it) const {
if (top == 0) return false;
else { it = listArray[top-1]; return true; }
}
int length() const { return top; }
void print() const{
if(top==0){
cout<<"The parking lot is empty."<<endl;
}
else{
cout << "The parking lot(from north to south,the door is at the south): "<<endl;
for(int i=0;i<top; i++)
cout<<listArray[i]<<" ";
cout<<endl;
}
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -