当前位置:网站首页>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();
*/
边栏推荐
猜你喜欢
《数字经济全景白皮书》金融数字用户篇 重磅发布!
微信小程序获取用户手机号码
为什么越来越多的开发者放弃使用Postman,而选择Eolink?
Matlab学习13-图像处理之可视化GUI程序
How to do App Automation Testing?Practical sharing of the whole process of App automation testing
c语言进阶篇:内存函数
GET 和 POST 有什么区别?
零信任的基本概念【新航海】
mysql advanced (twenty-four) method summary of defense against SQL injection
性能优化|从ping延时看CPU电源管理
随机推荐
什么是Weex
Simple implementation of a high-performance clone of Redis using .NET (1)
4500字归纳总结,一名软件测试工程师需要掌握的技能大全
第四周学习 HybridSN,MobileNet V1,V2,V3,SENet
899. 有序队列 : 最小表示法模板题
缓存--伪共享问题
What knowledge points do you need to master to learn software testing?
Traceback (most recent call last): File
深入理解MySQL事务MVCC的核心概念以及底层原理
第3章 搭建短视频App基础架构
基于英雄联盟的知识图谱问答系统
ssh 免密登录了解下
深度学习中数据到底要不要归一化?实测数据来说明!
C language advanced article: memory function
Blazor Server(6) from scratch--policy-based permission verification
【MySQL功法】第4话 · 和kiko一起探索MySQL中的运算符
肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
最牛逼的集群监控系统,它始终位列第一!
优维低代码:Provider 构件
为什么越来越多的开发者放弃使用Postman,而选择Eolink?