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 许可协议』进行许可. 消息队列处理后台任务带来的问题 项目中经常会有后台运行任务的需求,比如发送邮件时,因为要 ...
随机推荐
- Jenkins创建Maven项目及SSH部署
前面我们已经安装了Jenkins的环境,以及配置好了jdk和maven.下面我们来看如何通过Jenkins将svn的项目进行打包和部署. 创建MAVEN项目 1.点击新建,输入项目名,选择" ...
- xss篇-本着就了解安全本质的想法,尽可能的用通俗易懂的语言去解释安全漏洞问题
前言 最早接触安全也是从xss攻击和sql注入攻击开始的. 0x01 跨站脚本攻击漏洞(XSS),是客户端脚本安全中的头号大敌,owasp top10 屡居榜首,由于攻击手法较多,开发者水平不一 ...
- ABP 索引
官方网站 Github ABP集合贴 @ kebinet https://www.codeproject.com/articles/1115763/using-asp-net-core-entity- ...
- Android——Handler
Handler——是Android给我们提供用来更新UI的一套机制,也是一套消息处理机制,可以发送也可以处理消息 主要作用:1)在新启动的线程中发送消息:2)在主线程中获取.处理消息. (想想银行取钱 ...
- 发送ajax请求时页面被刷新
浏览器默认会认为 button 的属性是submit.type='submit',会发生提交表单的默认行为,为button添加type="button"即可.
- 【CoreAnimation】1 到 5
学习资源来自:图层树 . Quartz 2D Core Animation 复合引擎,职责为尽可能快地组合屏幕上不同的可视内容.这些内容被分解成多个独立的图层,存储在 图层树 的体系中.于是这个树形成 ...
- CSS-各种cs样式之浏览器兼容处理方式汇总大全(更新中...)
页面模板 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8"> 5 ...
- linux下libevent安装
wget http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz tar –xzvf libevent-1.4.13-stable.tar.gz ...
- HTML基础标签入门
HTML基础标签 昨天学习了一些HTML的基本标签以及基本属性: HTML是一种超文本标记语言,其中PHP是世界上最好的语言(增加学习的动力荣誉感). HTML文档里包含三部分: <html&g ...
- canvas变幻曲线
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...