当前位置:网站首页>622. 设计循环队列
622. 设计循环队列
2022-08-03 11:59:00 【anieoo】
原题链接:622. 设计循环队列

solution:
class MyCircularQueue {
public:
int hh = 0,tt = 0;
vector<int> q;
MyCircularQueue(int k) {
q.resize(k + 1);
}
bool enQueue(int value) {
if(isFull()) return false;
q[tt++] = value;
if(tt == q.size()) tt = 0;
return true;
}
bool deQueue() {
if (isEmpty()) return false;
hh ++ ;
if (hh == q.size()) hh = 0;
return true;
}
int Front() {
if(isEmpty()) return -1;
return q[hh];
}
int Rear() {
if (isEmpty()) return -1;
int t = tt - 1;
if (t < 0) t = q.size() - 1;
return q[t];
}
bool isEmpty() {
return hh == tt;
}
bool isFull() {
return (tt + 1) % q.size() == hh;
}
};
/**
* Your MyCircularQueue object will be instantiated and called as such:
* MyCircularQueue* obj = new MyCircularQueue(k);
* bool param_1 = obj->enQueue(value);
* bool param_2 = obj->deQueue();
* int param_3 = obj->Front();
* int param_4 = obj->Rear();
* bool param_5 = obj->isEmpty();
* bool param_6 = obj->isFull();
*/
边栏推荐
- 最牛逼的集群监控系统,它始终位列第一!
- Knowledge Graph Question Answering System Based on League of Legends
- 5个超好用手机开源自动化工具,哪个适合你?
- 为什么越来越多的开发者放弃使用Postman,而选择Eolink?
- CDH6.3.2开启kerberos认证
- FR9811S6 SOT-23-6 23V, 2A Synchronous Step-Down DC/DC Converter
- 实现2d人物在跳跃的同时左右移动
- 【Mysql】清理binlog日志的方法
- bash while循环和until循环
- 使用.NET简单实现一个Redis的高性能克隆版(一)
猜你喜欢

面试官:SOA 和微服务的区别?这回终于搞清楚了!

【MySQL功法】第2话 · 数据库与数据表的基本操作

性能优化|从ping延时看CPU电源管理

学习软件测试需要掌握哪些知识点呢?

word标尺有哪些作用

shell编程-测试

hystrix 服务熔断和服务降级

字节最爱问的智力题,你会几道?

"Digital Economy Panorama White Paper" Financial Digital User Chapter released!

How to do App Automation Testing?Practical sharing of the whole process of App automation testing
随机推荐
基于SSM和Web实现的农作物生长监控系统
Traceback (most recent call last): File
常用lambda表达式
子结点的数量
从零开始Blazor Server(6)--基于策略的权限验证
[Wrong title] Circuit maintenance
RTP协议分析
ThreadLocal源码解析及使用场景
Matlab学习10-图像处理之傅里叶变换
LeetCode 899 Ordered queue [lexicographical order] HERODING's LeetCode road
微信小程序获取手机号
hystrix 服务熔断和服务降级
零拷贝、MMAP、堆外内存,傻傻搞不明白...
5个超好用手机开源自动化工具,哪个适合你?
87.(cesium之家)cesium热力图(贴地形)
bash case usage
Matlab学习12-图像处理之图像增强
ROS中编译通过但是遇到可执行文件找不到的问题
-找树根2-
项目概述、推送和存储平台准备