c++队列基本功能
#include<string>
#include<assert.h>
#include<iostream>
typedef int status;
#define OK 1
#define ERROR 0
template<class type>
class order_tream
{
public:
order_tream(int a):size(a+1),n(0)
{
base =new type [a+1];
assert(base!=0);
front=0;
rear=0;
}
int n;
status full();//判断是否为满
status empty();//判断是否为空
void putin(int a);//输入
status enqueue(type a);//进队列
status sqqueue(type &a);//出队列
void clear();//清空
status out();//输出整个队列
private:
int rear;//尾
int front;//头
int size;
type* base;
};
/*进队列*/
template<class type>
status order_tream<type>::enqueue(type a)
{
if( full())
return ERROR;
base[rear]=a;
rear=(rear+1)%size;
n++;
return OK;
}
/*清空*/
template<class type>
void order_tream<type>::clear()
{
front=rear;
}
/*输入*/
template<class type>
void order_tream<type>::putin(int a)
{
type x;
cout<<"输入开始"<<endl;
for(int i=0;i<a;i++)
{
cin>>x;
enqueue(x);
}
}
/*出队列*/
template<class type>
status order_tream<type>::sqqueue(type& a)
{
if(empty())
return ERROR;
a=base[front];
front=(front+1)%size;
n--;
return OK;
}
/*判断是否为空*/
template<class type>
status order_tream<type>::empty()
{
if(front==rear)
return OK;
else
return ERROR;
}
/*判断是否为满*/
template<class type>
status order_tream<type>::full()
{
if(front==rear+1)
return OK;
else
return ERROR;
}
/*输出整个队列*/
template<class type>
status order_tream<type>::out()
{
if(empty())
return ERROR;
type a;
for(int i=0;i<n;i++)
{
a=base[i];
cout<<a<<'\t';
}
cout<<n;
cout<<endl;
return OK;
}
c++队列基本功能的更多相关文章
- 【springboot】【redis】springboot+redis实现发布订阅功能,实现redis的消息队列的功能
springboot+redis实现发布订阅功能,实现redis的消息队列的功能 参考:https://www.cnblogs.com/cx987514451/p/9529611.html 思考一个问 ...
- redis 的消息订阅和消息队列的功能比较
消息队列常用的有 rabitMQ.kafka等.缓存服务器 redis 也可以做消息队列使用,他们的特点对比如下 消息协议: 消息队列支持包括AMQP,MQTT,Stomp等,并且支持 JMS 规范 ...
- LinkedList(实现了queue,deque接口,List接口)实现栈和队列的功能
LinkedList是用双向链表结构存储数据的,很适合数据的动态插入和删除,随机访问和遍历速度比较慢. 底层是一个双向链表,链表擅长插入和删除操作,队列和栈最常用的2种操作都设计到插入和删除 impo ...
- 网络损伤仪WANsim的队列深度功能
什么是队列深度 在网络损伤仪WANsim中,队列是指一个用于缓存报文的缓冲池.深度是指缓冲池可以存储的最大数据量.当WANsim接受的报文超出了带宽限制的量时,溢出的报文会进入队列中. 我们可以在WA ...
- C#实现rabbitmq 延迟队列功能
最近在研究rabbitmq,项目中有这样一个场景:在用户要支付订单的时候,如果超过30分钟未支付,会把订单关掉.当然我们可以做一个定时任务,每个一段时间来扫描未支付的订单,如果该订单超过支付时间就关闭 ...
- oracle 队列
Oracle 高级队列(AQ) 适用对象:初步了解oracle高级队列人群 注意事项: 序号 注意事项 1 JMS监听部分可参考官方文档: http://docs.oracle.com/cd/e128 ...
- rabbitmq批量删除队列
有些时候,我们需要批量的删除rabbitmq中的队列,尤其是对于那些客户端配置了队列不存在时自动创建,但断开时不自动删除的应用来说. rabbitmqctl并没有包含直接管理队列的功能,其提供的vho ...
- Java多线程与并发库高级应用-可阻塞的队列
ArrayBlockQueue 可阻塞的队列 > 队列包含固定长度的队列和不固定长度的队列. > ArrayBlockQueue > 看BlockingQueue类的帮助文档,其中有 ...
- PHP的轻量消息队列php-resque使用说明
日志未经声明,均为AlloVince原创.版权采用『 知识共享署名-非商业性使用 2.5 许可协议』进行许可. 消息队列处理后台任务带来的问题 项目中经常会有后台运行任务的需求,比如发送邮件时,因为要 ...
随机推荐
- C#-WebForm-Request、Response、QueryString、Repeater删
知识点: Request - 获取请求对象 专门用来接传递过来的值 Request["key"](李献策lxc) 1.获取地址栏传递过来的值 get 2.获取表单传递过来的参数值 ...
- POJ 1966 Cable TV Network
Cable TV Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 4702 Accepted: 2173 ...
- 【bzoj2648】 SJY摆棋子
http://www.lydsy.com/JudgeOnline/problem.php?id=2648 (题目链接) 题意 动态维护二维平面上的点的插入以及最邻近域搜索. Solution KDtr ...
- 【JavaWeb】Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(一)
Spring+MyBatis 首先要搭建的是Spring+MyBatis的整合框架,毕竟Spring是整个Web框架的核心部位,而数据库操作是一切测试的基础嘛. 目录结构 ━java ┣ contro ...
- UVA1625Color Lenth(DP+LCS变形 未AC)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/C 紫书P276 res[i][j]表示第一个序列移动i个,第 ...
- JS 小数的常用处理方法
1.丢弃小数部分,保留整数部分 parseInt(5/2) 2.向上取整,有小数就整数部分加1 Math.ceil(5/2) 3,四舍五入. Math.round(5/2) 4,向下取整 Math.f ...
- variadic function 的使用
最近在看<the c programming language> K&R 7.3章 Variable-length Argument Lists 变长参数列表, 笔记一下用法 1 ...
- vim + ctags + taglist配置和使用
vim +ctags + taglist ,ctags+cscope 安装配置和使用 内容:VIM下ctags和taglist的安装配置方法:一键安装 ctags和cscope的方法 :vim语法高亮 ...
- 用Canvas实现动画效果
1.清除Canvas的内容 clearRect(x,y,width,height)函数用于清除图像中指定矩形区域的内容 <!doctype html> <html> <h ...
- HttpContext.Cache属性
HttpContext基于HttpApplication的处理管道,由于HttpContext对象贯穿整个处理过程,所以,可以从HttpApplication处理管道的前端将状态数据传递到管道的后端, ...