您的位置:首页 > 其它

"《算法导论》之‘队列’":队列的三种实现(静态数组、动态数组及指针)

2014-11-04 21:30 246 查看
  本文有关栈的介绍部分参考自网站数据结构

  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/.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: