Essential c++ 第四章课后练习

练习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 移除栈顶元素
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值