#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++队列基本功能的更多相关文章

  1. 【springboot】【redis】springboot+redis实现发布订阅功能,实现redis的消息队列的功能

    springboot+redis实现发布订阅功能,实现redis的消息队列的功能 参考:https://www.cnblogs.com/cx987514451/p/9529611.html 思考一个问 ...

  2. redis 的消息订阅和消息队列的功能比较

    消息队列常用的有 rabitMQ.kafka等.缓存服务器  redis 也可以做消息队列使用,他们的特点对比如下 消息协议: 消息队列支持包括AMQP,MQTT,Stomp等,并且支持 JMS 规范 ...

  3. LinkedList(实现了queue,deque接口,List接口)实现栈和队列的功能

    LinkedList是用双向链表结构存储数据的,很适合数据的动态插入和删除,随机访问和遍历速度比较慢. 底层是一个双向链表,链表擅长插入和删除操作,队列和栈最常用的2种操作都设计到插入和删除 impo ...

  4. 网络损伤仪WANsim的队列深度功能

    什么是队列深度 在网络损伤仪WANsim中,队列是指一个用于缓存报文的缓冲池.深度是指缓冲池可以存储的最大数据量.当WANsim接受的报文超出了带宽限制的量时,溢出的报文会进入队列中. 我们可以在WA ...

  5. C#实现rabbitmq 延迟队列功能

    最近在研究rabbitmq,项目中有这样一个场景:在用户要支付订单的时候,如果超过30分钟未支付,会把订单关掉.当然我们可以做一个定时任务,每个一段时间来扫描未支付的订单,如果该订单超过支付时间就关闭 ...

  6. oracle 队列

    Oracle 高级队列(AQ) 适用对象:初步了解oracle高级队列人群 注意事项: 序号 注意事项 1 JMS监听部分可参考官方文档: http://docs.oracle.com/cd/e128 ...

  7. rabbitmq批量删除队列

    有些时候,我们需要批量的删除rabbitmq中的队列,尤其是对于那些客户端配置了队列不存在时自动创建,但断开时不自动删除的应用来说. rabbitmqctl并没有包含直接管理队列的功能,其提供的vho ...

  8. Java多线程与并发库高级应用-可阻塞的队列

    ArrayBlockQueue 可阻塞的队列 > 队列包含固定长度的队列和不固定长度的队列. > ArrayBlockQueue > 看BlockingQueue类的帮助文档,其中有 ...

  9. PHP的轻量消息队列php-resque使用说明

    日志未经声明,均为AlloVince原创.版权采用『 知识共享署名-非商业性使用 2.5 许可协议』进行许可. 消息队列处理后台任务带来的问题 项目中经常会有后台运行任务的需求,比如发送邮件时,因为要 ...

随机推荐

  1. Python学习--Python 环境搭建

    Python环境搭建 Python是跨平台的编程语言,可应用于Windows.Linux.Mac OS X.你可以通过终端窗口输入"python"命令来查看本地是否安装了Pytho ...

  2. [转]HQL中的子查询

    原文地址:http://blog.csdn.net/xb12369/article/details/8638683 子查询:   子查询是SQL语句中非常重要的功能特性,它可以在SQL语句中利用另外一 ...

  3. echarts-案例

    关系图 http://echarts.baidu.com/echarts2/doc/example/force1.html http://www.cnblogs.com/spring_wang/p/4 ...

  4. JsonResult类设置返回json的长度(工作笔记 json转化出错)

    public JsonResult PoundageReportSearch()         {    JsonResult jr = new JsonResult();        // 实例 ...

  5. FilenameFilter过滤文件名

    前言: 文件IO是程序设计语言的一个特点,本文将针对Java的File文件名过滤进行测试. 测试目录截图: 测试结果: data.txt output-.txt output-.txt output- ...

  6. 源码编译安装postgresql

    依赖的库:libreadline-dev,zlib1g-dev 安装:下载解压源码包,然后 ./configure,make,make install即可.. 注意不能在root账户下跑server, ...

  7. MySQL索引原理及慢查询优化

    原文:http://tech.meituan.com/mysql-index.html 一个慢查询引发的思考 select count(*) from task where status=2 and ...

  8. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

  9. mysql 数据类型拾遗

    写这篇博客的原因是在建表的过程我建表时,在表名和字段名上没有注意,违背了团队的开发规范.我们团队规范是,名字上要能够体现对象的特征. 比如: 数据库要写db_dbname 表名要写tb_tbname ...

  10. 如何解决Maven和SBT下载Jar包太慢

    国内:如何解决Maven和SBT下载Jar包太慢 Maven 远程仓库 <mirror> <id>ui</id> <mirrorOf>central&l ...