当前位置:网站首页>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();
*/
边栏推荐
- 第3章 搭建短视频App基础架构
- GET 和 POST 有什么区别?
- Vs Shortcut Keys---Explore Different Programming
- 【一起学Rust 基础篇】Rust基础——变量和数据类型
- Simple implementation of a high-performance clone of Redis using .NET (1)
- Five super handy phone open-source automation tools, which is suitable for you?
- How to do App Automation Testing?Practical sharing of the whole process of App automation testing
- JUC(三):锁核心类AQS ing
- Knowledge Graph Question Answering System Based on League of Legends
- 矩阵的计算[通俗易懂]
猜你喜欢
随机推荐
899. 有序队列 : 最小表示法模板题
第4章 搭建网络库&Room缓存框架
flink流批一体有啥条件,数据源是从mysql批量分片读取,为啥设置成批量模式就不行
SmobilerService 推送实现
小身材有大作用——光模块寿命分析(二)
通过组策略安装软件和删除用户配置文件
Knowledge Graph Question Answering System Based on League of Legends
最牛逼的集群监控系统,它始终位列第一!
记住用户名案例(js)
一文带你弄懂 CDN 技术的原理
LeetCode-142. 环形链表 II
I in mother's womb SOLO20 years
数据库系统原理与应用教程(074)—— MySQL 练习题:操作题 141-150(十八):综合练习
opencv学习—VideoCapture 类基础知识「建议收藏」
OFDM 十六讲 4 -What is a Cyclic Prefix in OFDM
C language advanced article: memory function
面试官:SOA 和微服务的区别?这回终于搞清楚了!
Take you understand the principle of CDN technology
shell编程-测试
bash for循环