当前位置:网站首页>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();
*/
边栏推荐
- MySQL之json数据操作
- 字节最爱问的智力题,你会几道?
- 记住用户名案例(js)
- Five super handy phone open-source automation tools, which is suitable for you?
- 【云原生 · Kubernetes】部署Kubernetes集群
- 赛灵思MPSOC裸机下的 USB调试实验
- 长城简漫·暑期安全篇⑤ 这个强,不能逞
- 深度学习:文本CNN-textcnn
- PC client automation testing practice based on Sikuli GUI image recognition framework
- Lease recovery system based on PHP7.2+MySQL5.7
猜你喜欢

Matlab学习11-图像处理之图像变换

《数字经济全景白皮书》金融数字用户篇 重磅发布!

mysql进阶(二十四)防御SQL注入的方法总结

分享一款实用的太阳能充电电路(室内光照可用)

4500 words sum up, a software test engineer need to master the skill books

ROS中编译通过但是遇到可执行文件找不到的问题

After completing the interview and clearance collection of Alibaba, I successfully won the 15th Offer this year

html网页如何获取后台数据库的数据(html + ajax + php + mysql)

Explain the virtual machine in detail!JD.com produced HotSpot VM source code analysis notes (with complete source code)

后台图库上传功能
随机推荐
字节最爱问的智力题,你会几道?
为什么越来越多的开发者放弃使用Postman,而选择Eolink?
net start mysql 启动报错:发生系统错误5。拒绝访问。
ssh 免密登录了解下
实现2d人物在跳跃的同时左右移动
html+css+php+mysql实现注册+登录+修改密码(附完整代码)
【JS 逆向百例】某网站加速乐 Cookie 混淆逆向详解
Objective - C code analysis of the deep and shallow copy
用C语言解决A+B问题,A-B问题,A*B问题
学习软件测试需要掌握哪些知识点呢?
零信任架构分析【扬帆】
bash case usage
LeetCode——1161. 最大层内元素和
SmobilerService 推送实现
Generate interface documentation online
【Mysql】清理binlog日志的方法
劝退背后。
[Wrong title] Circuit maintenance
想学自动化测试网课哪个好?过了人告诉你:适合自己的才是最重要
LeetCode-142. 环形链表 II