博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C++ 循环队列基本算法实现
阅读量:6870 次
发布时间:2019-06-26

本文共 1134 字,大约阅读时间需要 3 分钟。

C++ 循环队列基本算法实现

#ifndef CircleQueue_h#define CircleQueue_hconst int QueueSize = 1000;template 
class CircleQueue{public: CircleQueue(){front = rear = 0;} void EnQueue(T x); T DeQueue(); T GetFront(); void SetNull(); int GetLength(); bool Empty(){
return front == rear ? true : false;}private: T data[QueueSize]; int front; int rear;};template
void CircleQueue
::EnQueue(T x){ if((rear+1)%QueueSize == front) throw "overflow"; rear = (rear + 1)%QueueSize; //队尾指向下一个位置 data[rear] = x;}template
T CircleQueue
::DeQueue(){ if(front == rear) throw "the Queue is null"; front = (front+1)%QueueSize; T x = data[front]; return x;}template
T CircleQueue
::GetFront(){ if(front == rear) throw "the Queue is null"; return data[(front +1)%QueueSize];}template
int CircleQueue
::GetLength(){ return (rear-front +QueueSize)%QueueSize;}template
void CircleQueue
::SetNull(){ rear = 0; front = 0;}#endif /* CircleQueue_h */

 

转载于:https://www.cnblogs.com/ycbeginner/p/10006413.html

你可能感兴趣的文章
【原创翻译】布尔值(boolean)
查看>>
三元运算式、lambda表达式、内置函数map、reduce、filter以及yield生成器
查看>>
MySQL分库分表分表后数据的查询(5th)
查看>>
iOS-点击图片放大,再次点击返回原视图 类似查看相册的功能
查看>>
JAVA -- stateless4j StateMachine 使用浅析(二)
查看>>
oracle checkpoint
查看>>
KVM虚拟化开源高可用方案(六)ISCSI ON DRBD搭建及常见故障处理
查看>>
android device related
查看>>
iOS 6 Beta3即将发布,iPhone面板谍照已经曝光
查看>>
hadoop 源码包编译
查看>>
h5存储的优点
查看>>
Python基础之各种推导式玩法
查看>>
[HNOI/AHOI2017]影魔
查看>>
微信小程序-多级联动
查看>>
Ubuntu配置MYSQL远程连接
查看>>
docker-1-简介
查看>>
PAT 1020
查看>>
tcp端口扫描(python多线程)
查看>>
W3CSchool闯关笔记(Bootstrap)
查看>>
洛谷 P3742 umi的函数【构造】
查看>>