⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 astack.h

📁 数据结构实验——停车场管理系统 停车场管理。设停车场内只有一个可停放几辆汽车的狭长通道
💻 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 + -