资源简介
C++程序设计语言特别版源码
C++程序设计语言特别版源码
C++程序设计语言特别版源码

代码片段和文件信息
/* 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 C++程序设计语言特别版源码\Ch10\ex10_12a.cpp
文件 2890 1998-09-06 19:29 C++程序设计语言特别版源码\Ch10\ex10_12b.cpp
文件 807 1998-09-06 19:29 C++程序设计语言特别版源码\Ch10\ex10_15.cpp
文件 2703 1998-09-06 19:30 C++程序设计语言特别版源码\Ch10\ex10_19.cpp
文件 1970 1998-09-06 19:30 C++程序设计语言特别版源码\Ch10\ex10_5.cpp
文件 2263 1998-09-06 19:30 C++程序设计语言特别版源码\Ch11\ex11_1.cpp
文件 781 1998-09-06 19:31 C++程序设计语言特别版源码\Ch11\ex11_10.cpp
文件 1014 1998-09-06 19:31 C++程序设计语言特别版源码\Ch11\ex11_21.cpp
文件 1624 1998-09-06 19:31 C++程序设计语言特别版源码\Ch11\ex11_4.cpp
文件 1195 1998-09-06 19:32 C++程序设计语言特别版源码\Ch11\ex11_8.cpp
文件 5176 1998-09-06 19:43 C++程序设计语言特别版源码\Ch11\str.hpp
文件 3139 1998-09-06 19:32 C++程序设计语言特别版源码\Ch12\ex12_10.cpp
文件 1072 1998-09-06 19:32 C++程序设计语言特别版源码\Ch12\ex12_1a.cpp
文件 1031 1998-09-06 19:32 C++程序设计语言特别版源码\Ch12\ex12_1b.cpp
文件 1378 1998-09-06 19:32 C++程序设计语言特别版源码\Ch12\ex12_9.cpp
文件 934 1998-09-06 19:33 C++程序设计语言特别版源码\Ch13\ex13_15.cpp
文件 4753 1998-09-06 19:33 C++程序设计语言特别版源码\Ch13\ex13_2.cpp
文件 2046 1998-09-06 19:33 C++程序设计语言特别版源码\Ch14\ex14_1.cpp
文件 1627 1998-09-06 19:33 C++程序设计语言特别版源码\Ch14\ex14_10.cpp
文件 3487 1998-09-06 19:33 C++程序设计语言特别版源码\Ch14\ex14_2.cpp
文件 3041 1998-09-06 19:33 C++程序设计语言特别版源码\Ch15\ex15_2.cpp
文件 2939 1998-09-06 19:44 C++程序设计语言特别版源码\Ch15\Ex15_3\Board.C
文件 1365 1998-09-06 19:44 C++程序设计语言特别版源码\Ch15\Ex15_3\Board.H
文件 1399 1998-09-06 19:45 C++程序设计语言特别版源码\Ch15\Ex15_3\BoardTextViewer.C
文件 935 1998-09-06 19:45 C++程序设计语言特别版源码\Ch15\Ex15_3\BoardTextViewer.H
文件 703 1998-09-06 19:45 C++程序设计语言特别版源码\Ch15\Ex15_3\BoardViewer.H
文件 1529 1998-09-06 19:48 C++程序设计语言特别版源码\Ch15\Ex15_3\Game.C
文件 946 1998-09-06 19:46 C++程序设计语言特别版源码\Ch15\Ex15_3\Game.H
文件 2305 1998-09-06 19:46 C++程序设计语言特别版源码\Ch15\Ex15_3\HumanTextPla
文件 1166 1998-09-06 19:46 C++程序设计语言特别版源码\Ch15\Ex15_3\HumanTextPla
............此处省略129个文件信息
- 上一篇:C++实现播放GIF图片
- 下一篇:飞机订票系统,c++程序
相关资源
- C++中头文件与源文件的作用详解
- C++多线程网络编程Socket
- VC++ 多线程文件读写操作
- C语言课程设计
- 数字电位器C语言程序
- CCS FFT c语言算法
- 通信过程中的RS编译码程序(c语言)
- 利用C++哈希表的方法实现电话号码查
- 移木块游戏,可以自编自玩,vc6.0编写
- 简单的C语言点对点聊天程序
- 单片机c语言源程序(51定时器 八个按
- C++纯文字DOS超小RPG游戏
- c语言电子商务系统
- 将图片转换为C语言数组的程序
- 安科瑞智能电能表MODBUS通讯程序 VC6
- C语言实现的一个内存泄漏检测程序
- 用单片机控制蜂鸣器播放旋律程序(
- 电子时钟 有C语言程序,PROTEUS仿真图
- 基于C语言的密码锁程序
- VC++MFC小游戏实例教程(实例)+MFC类库
- c语言小学生自然数四则运算测试程序
- c语言程序设计报告 程序大全
- 文件传输和聊天程序(c语言实现)
- 连铸温度场计算程序(C++)
- 6自由度机器人运动学正反解C++程序
- Em算法(使用C++编写)
- 基于C语言实现的网络爬虫(搜索引擎
- libstdc++-4.4.7-4.el6.i686.rpm
- VC++实现CMD命令执行与获得返回信息
- 白话C++(全)
评论
共有 条评论