2019-A

benbenlzw / 2023-07-03 / 原文

#include <iostream>
#include <vector>

using namespace std;

class Mystack{
	private:
		int top;
		vector<int> data;
	public:
		Mystack(){
			top=0;
			data.push_back(-1);
		}
		
		void push(int x){
			data.push_back(x);
			top++;
		}
		void pop(){
			data.pop_back();
			top--;
		} 
		
		bool isEmpty(){
			if(data[top]==-1)	return true;
			else	return false;
		}
		
		int get_top(){
			return data[top];
		}
};

int main(){
	Mystack stack;
	cout<<"----1 represent the stack is empty!----"<<endl;
	cout<<stack.isEmpty()<<endl;
	int x;
	while(cin>>x)	stack.push(x);
	cout<<"----print the stack from top to bottom----"<<endl;
	while(!stack.isEmpty())	{
		cout<<stack.get_top()<<endl;
		stack.pop();
	}
	return 0;
}