头文件stack.h:
#include<vector>
#include<string>
using namespace std;
class stack
{
public:
bool push(const string&);
bool pop(string &elem);
bool peek(string &elem);
bool empty()const{return _stack.empty();}
bool full()const{return _stack.size()==_stack.max_size();}
private:
vector<string>_stack;
}
CPP文件stack.cpp:
#include "stack.h"
bool stack::pop(string &elem)
{
if(empty())return false;
elem=_stack.back();
_stack.pop_back();
return true;
}
bool stack::peek(string &elem){
if(empty())return false;
elem=_stack.back();
return true;
}
bool stack::push(const string &elem){
if (full())return false;
_stack.push_back(elem);
return true;
}
#include<vector>
#include<string>
using namespace std;
class stack
{
public:
bool push(const string&);
bool pop(string &elem);
bool peek(string &elem);
bool empty()const{return _stack.empty();}
bool full()const{return _stack.size()==_stack.max_size();}
private:
vector<string>_stack;
}
CPP文件stack.cpp:
#include "stack.h"
bool stack::pop(string &elem)
{
if(empty())return false;
elem=_stack.back();
_stack.pop_back();
return true;
}
bool stack::peek(string &elem){
if(empty())return false;
elem=_stack.back();
return true;
}
bool stack::push(const string &elem){
if (full())return false;
_stack.push_back(elem);
return true;
}