练习4.1-4.2
Stack.h 头文件
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
//class主体
class Stack {
public:
bool push(const string&);
bool pop(string &elem);
bool peek(string &elem);
bool find(const string &elem) ;
int count(const string &elem);
//以上五个成员函数全是申明
//以下三个成员函数直接定义于class本身中
bool empty() {
return _stack.empty(); }
bool full() {
return _stack.size() == _stack.max_size(); }
int size() {
return _stack.size(); }
private:
vector<string> _stack;
};
//class主体之外定义成员函数
bool
Stack::pop(string &elem) //pop 移除栈顶元素