"《算法导论》之‘队列’":队列的三种实现(静态数组、动态数组及指针)
2014-11-04 21:30
246 查看
本文有关栈的介绍部分参考自网站数据结构。
BoostUnitTest.cpp
本篇博文的代码均托管到Taocode : http://code.taobao.org/p/datastructureandalgorithm/src/.
1. 队列
1.1 队列的定义
队列(Queue)是只允许在一端进行插入,而在另一端进行删除的运算受限的线性表。#define BOOST_TEST_MODULE Stack_Test_Module #include "stdafx.h" #include "../Queue/queue.hpp" const int MAXSIZE = 3; struct Stack_Fixture { public: Stack_Fixture() { testQueue = new Queue<int, MAXSIZE>(); } ~Stack_Fixture() { delete testQueue; } Queue<int, MAXSIZE> * testQueue; }; BOOST_FIXTURE_TEST_SUITE(Stack_Test_Fixture, Stack_Fixture) BOOST_AUTO_TEST_CASE(Queue_Test) { // isEmpty ------------------------------------ BOOST_REQUIRE(testQueue->isEmpty() == true); // isEmpty ------------------------------------ BOOST_REQUIRE(testQueue->getSizeOfQueue() == 0); // enQueue & front --------------------------------- BOOST_REQUIRE(testQueue->enQueue(1) == true); BOOST_REQUIRE(testQueue->front() == 1); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 1); BOOST_REQUIRE(testQueue->enQueue(2) == true); BOOST_REQUIRE(testQueue->front() == 1); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 2); BOOST_REQUIRE(testQueue->enQueue(3) == true); BOOST_REQUIRE(testQueue->front() == 1); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 3); BOOST_REQUIRE(testQueue->enQueue(3) == false); BOOST_REQUIRE(testQueue->front() == 1); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 3); // deQueue & front ---------------------------------- BOOST_REQUIRE(testQueue->deQueue() == true); BOOST_REQUIRE(testQueue->front() == 2); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 2); BOOST_REQUIRE(testQueue->deQueue() == true); BOOST_REQUIRE(testQueue->front() == 3); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 1); BOOST_REQUIRE(testQueue->deQueue() == true); BOOST_REQUIRE(testQueue->getSizeOfQueue() == 0); BOOST_REQUIRE(testQueue->deQueue() == false); } BOOST_AUTO_TEST_SUITE_END()
BoostUnitTest.cpp
2.2 基于动态数组
请参考栈的三种实现(静态数组、动态数组及指针)2.2。2.3 基于指针
请参考栈的三种实现(静态数组、动态数组及指针)2.3。本篇博文的代码均托管到Taocode : http://code.taobao.org/p/datastructureandalgorithm/src/.
相关文章推荐
- "《算法导论》之‘栈’":栈的三种实现(静态数组、动态数组及指针)
- "《算法导论》之‘线性表’":基于静态分配的数组的顺序表
- "《算法导论》之‘线性表’":基于数组实现的单链表
- 静态数组实现循环队列
- "《算法导论》之‘线性表’":基于指针实现的单链表
- Delphi 指针, 静态数组, 动态数组
- 栈和队列的数组实现—《算法导论》学习笔记之六
- 《算法导论》学习笔记之Chapter10---队列的数组实现
- 用数组实现队列--静态队列
- 基础知识--数组、栈、队列的静态、动态和链式实现
- 队列,数组实现,指针实现的源码详细讲解
- "《算法导论》之‘线性表’":基于动态分配的数组的顺序表
- C++用数组实现的静态队列
- 静态数组实现的队列
- mysql存储过程以"数组"形式入参实现表间复制 并实现回滚
- c语言数组方式实现静态循环队列
- 循环队列的判断满、空的三种方法以及具体代码实现(数组实现)
- 算法导论学习10.1 两个栈共享一个数组 and 两个栈实现一个队列 and 两个队列实现一个栈
- 如何 "使用" 静态方法约束实现类或子类
- 静态数组实现队列(C语言)