资源简介
这个是C++之父的著作 The C++ PL的特别版的课后习题答案,希望对大家有用,
代码片段和文件信息
/* Code for exercise 10.12.
|
| “C++ Solutions--Companion to The C++ Programming Language Third Edition“
| by David Vandevoorde; Addison-Wesley 1998; ISBN 0-201-30965-3.
|
| Permission to use copy modify distribute and sell this software
| and its documentation for any purpose is hereby granted without fee.
| The author makes no representations about the suitability of this
| software for any purpose. It is provided “as is“ without express or
| implied warranty.
‘----------------------------------------------------------------------*/
#include
#include
/* The following can go in a header file */
#include
#include
struct Char_queue {
inline Char_queue(unsigned capacity = default_capacity);
~Char_queue() { delete[] queue_; }
bool empty() const { return head_==tail_; }
inline char dequeue();
inline void enqueue(char);
bool full() const { return head_==(tail_+1)%capacity_; }
static bool const fixed_capacity = true;
private:
static unsigned const default_capacity = 32;
char *queue_;
unsigned head_ tail_;
unsigned const capacity_;
};
inline
Char_queue::Char_queue(unsigned n)
: queue_(new char[n+1]) head_(0) tail_(0) capacity_(n+1) {
}
inline
char Char_queue::dequeue() {
if (!empty()) {
char c = queue_[head_];
head_ = (head_+1)%capacity_;
return c;
} else
throw std::underflow_error(std::string(“queue“));
}
inline
void Char_queue::enqueue(char c) {
if (!full()) {
queue_[tail_] = c;
tail_ = (tail_+1)%capacity_;
} else
throw std::overflow_error(std::string(“queue“));
}
/* Header file would stop here. */
/* A brief test of the above implementation: */
int main() {
Char_queue q(4);
while (1) {
if (q.empty()) { std::cout << “Queue is empty.\n“; }
else if (q.full()) { std::cout << “Queue is full.\n“; }
char cmd ch;
std::cin >> cmd;
try {
switch (cmd) {
case ‘e‘: case ‘E‘:
std::cin >> ch;
q.enqueue(ch);
break;
case ‘d‘: case ‘D‘:
std::cout << “Dequeued “ << q.dequeue() << ‘\n‘;
break;
case ‘q‘: case ‘Q‘:
std::cout << “Quitting!\n“;
return 0;
default:
std::cerr << “Invalid command!\n“;
}
} catch (std::exception &x) {
std::cerr << “Caught exception “ << typeid(x).name()
<< “ (“ << x.what() << “)\n“;
}
}
return 0;
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 2626 1998-09-06 19:29 课后题解答\Ch10\ex10_12a.cpp
文件 2890 1998-09-06 19:29 课后题解答\Ch10\ex10_12b.cpp
文件 807 1998-09-06 19:29 课后题解答\Ch10\ex10_15.cpp
文件 2703 1998-09-06 19:30 课后题解答\Ch10\ex10_19.cpp
文件 1970 1998-09-06 19:30 课后题解答\Ch10\ex10_5.cpp
文件 2263 1998-09-06 19:30 课后题解答\Ch11\ex11_1.cpp
文件 781 1998-09-06 19:31 课后题解答\Ch11\ex11_10.cpp
文件 1014 1998-09-06 19:31 课后题解答\Ch11\ex11_21.cpp
文件 1624 1998-09-06 19:31 课后题解答\Ch11\ex11_4.cpp
文件 1195 1998-09-06 19:32 课后题解答\Ch11\ex11_8.cpp
文件 5176 1998-09-06 19:43 课后题解答\Ch11\str.hpp
文件 3139 1998-09-06 19:32 课后题解答\Ch12\ex12_10.cpp
文件 1072 1998-09-06 19:32 课后题解答\Ch12\ex12_1a.cpp
文件 1031 1998-09-06 19:32 课后题解答\Ch12\ex12_1b.cpp
文件 1378 1998-09-06 19:32 课后题解答\Ch12\ex12_9.cpp
文件 934 1998-09-06 19:33 课后题解答\Ch13\ex13_15.cpp
文件 4753 1998-09-06 19:33 课后题解答\Ch13\ex13_2.cpp
文件 2046 1998-09-06 19:33 课后题解答\Ch14\ex14_1.cpp
文件 1627 1998-09-06 19:33 课后题解答\Ch14\ex14_10.cpp
文件 3487 1998-09-06 19:33 课后题解答\Ch14\ex14_2.cpp
文件 3041 1998-09-06 19:33 课后题解答\Ch15\ex15_2.cpp
文件 2939 1998-09-06 19:44 课后题解答\Ch15\Ex15_3\Board.C
文件 1365 1998-09-06 19:44 课后题解答\Ch15\Ex15_3\Board.H
文件 1399 1998-09-06 19:45 课后题解答\Ch15\Ex15_3\BoardTextViewer.C
文件 935 1998-09-06 19:45 课后题解答\Ch15\Ex15_3\BoardTextViewer.H
文件 703 1998-09-06 19:45 课后题解答\Ch15\Ex15_3\BoardViewer.H
文件 1529 1998-09-06 19:48 课后题解答\Ch15\Ex15_3\Game.C
文件 946 1998-09-06 19:46 课后题解答\Ch15\Ex15_3\Game.H
文件 2305 1998-09-06 19:46 课后题解答\Ch15\Ex15_3\HumanTextPla
文件 1166 1998-09-06 19:46 课后题解答\Ch15\Ex15_3\HumanTextPla
............此处省略116个文件信息
相关资源
- 通讯录管理系统c++版顺序表存储,折
- 初学者学习C++ Builder第一个程序模拟聊
- 初学者学习C++ Builder第一个程序模拟聊
- Disruptor C++版(仅支持单生产者)
- Visual C++开发大全提高卷)光盘资料
- 用C++栈写的中缀表达式求解
- c++线程安全日志类
- MFC视频播放器(带播放列表VC++6.0源代
- C++primer第五版习题答案及解析
- 八数码问题C++代码
- winhttp 异步c++库
- 学生选课管理系统 C++
- 双目视觉标定棋盘格模板程序
- VC++调用大漠插件
- VC++用MKL产生正态分布随机数、计算样
- 04737 c++程序设计 自考课后练习答案
- C++_与电脑玩21点游戏.zip
- C语言 个人通讯录管理系统
- 浙工大C++通关考模拟题代码
- c++rpg游戏(带存档)
- 数据结构上机题
- Qt/C++ 网站爬虫源码
- 图像处理-读取bmp图像均值滤波-C++
- 图的建立与遍历c++实现邻接矩阵存储
- 骑士周游列国(跳马问题)C++代码实
- VC++ 使用RSA算法防止非法注册机破解软
- VC++开发GIS系统代码陈建春书
- shallow water equation c++ code
- C++实现小型数据库DBMS,具备建表以及
- 模拟的DBMS
评论
共有 条评论