data structure --Queue(基于数组的实现)
来源:互联网 发布:pc网络格斗游戏排行榜 编辑:程序博客网 时间:2024/06/06 08:49
#include<iostream>using namespace std;const int maxqueue=10;template <class T>class ArrayQueue{public:ArrayQueue();bool empty() const; bool full() const;int size() const;void append(T &item);void serve();T& retrieve();void clear();private:int count;int front,rear;T array[maxqueue];};template <class T>ArrayQueue<T>::ArrayQueue()/*Pre: None Post: The Queue is initialized to be empty.*/{count=0;front=0;rear=maxqueue-1;}template <class T>bool ArrayQueue<T>::empty() const/*Pre: None Post: Return true if the Queue is empty,otherwise return false.*/{return count==0;}template <class T>bool ArrayQueue<T>::full() const/*Pre:None Post:If the queue is full,true is returned.Otherwise,false is returned*/{return count==10;}template <class T>int ArrayQueue<T>::size() const/*Pre:None Post:Return the number of entries in the queue.*/{return count;}template <class T>void ArrayQueue<T>::append(T &item)/*Pre: None Post: Item is added to the rear of the Queue if it is not full,otherwise the queue is left unchanged.*/{if(count<maxqueue) { count++; rear=((rear+1)==maxqueue)?0:(rear+1); array[rear]=item; } }template <class T>void ArrayQueue<T>::serve()/*Pre: None Post: The front of the Queue is removed if the queue is not empty.*/{if(count>0){count--;front=((front+1)==maxqueue)?0:(front+1);}}template <class T>T& ArrayQueue<T>::retrieve()/*Pre: None Post: The front of the Queue is returnd if the queue is not empty.*/{if(count>0) return array[front];}template <class T>void ArrayQueue<T>::clear()/*Pre: None Post: The Queue is reset to be empty.*/{count=0;front=0;rear=maxqueue-1;}
0 0
- data structure --Queue(基于数组的实现)
- data structure--Stack(基于数组实现)
- Data Structure-2 Queue 循环队列,用数组实现
- Stack & Queue--Data Structure
- Priority Queue--Data Structure
- 【Data Structure】树状数组
- 基于数组的队列Queue
- 【Data Structure & Algorithm】求子数组的最大和
- I Can Guess the Data Structure!(水题,不过锻炼了stack,queue,priority的用法)
- 基于动态数组的Queue类
- UVA11995I Can Guess the Data Structure!(stack + queue + priority_queue)
- HDU 4217 Data Structure? 树状数组
- hdu 4217 Data Structure?(树状数组)
- Hdu 4217 Data Structure?【二分+树状数组】
- Data Structure导论的导论
- 基于数组实现Java 自定义Queue队列及应用
- Structure.Queue 队列(包含顺序队列,链表队列的实现)
- 【Data Structure/Algorithm】LCSS算法实现
- 无处不在的家
- 1.SQL Server DML触发器之AFTER触发器
- iOS: iOS视图控制器编程指南 目录
- Overview of ORA-1000 Maximum Number of Cursors Exceeded (文档 ID 1012266.6)
- mysql join -- 详细
- data structure --Queue(基于数组的实现)
- VC实现FTP上传和下载
- Floyd 最短路径
- (湖北)电信、移动、联通DNS
- Python注释
- CAAnimation
- 0021 Java虚拟机关闭前的钩子调用【基础】
- 机器学习&数据挖掘笔记_20(PGM练习四:图模型的精确推理)
- android 9patch背景图片导致的一个文本显示问题