当前位置:网站首页>365天挑战LeetCode1000题——Day 047 设计循环队列 循环队列
365天挑战LeetCode1000题——Day 047 设计循环队列 循环队列
2022-08-02 10:28:00 【ShowM3TheCode】
622. 设计循环队列

代码实现(首刷自解)
class MyCircularQueue {
private:
int* q;
int front, rear, size, maxSize;
public:
MyCircularQueue(int k) : q(new int[k]), front(0), rear(0), size(0),
maxSize(k) {
}
bool enQueue(int value) {
if (isFull()) return false;
q[rear] = value;
rear = (rear + 1) % maxSize;
size++;
return true;
}
bool deQueue() {
if (isEmpty()) return false;
front = (front + 1) % maxSize;
size--;
return true;
}
int Front() {
if (isEmpty()) return -1;
return q[front];
}
int Rear() {
if (isEmpty()) return -1;
return q[(maxSize + rear - 1) % maxSize];
}
bool isEmpty() {
return !size;
}
bool isFull() {
return size == maxSize;
}
};
/** * 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(); */
边栏推荐
- 阿里巴巴 CTO 程立:开源是基础软件的源头!
- LayaBox---TypeScript---JSX
- 如何选择一块真正“好用的、性能高”的远程控制软件
- 行为型模式-策略模式
- ASP.NET Core 6框架揭秘实例演示[31]:路由"高阶"用法
- Com多进程通信实现
- 新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
- The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
- LayaBox---TypeScript---Mixins
- 21年毕业转行软件测试,从0收入到月薪过万,我真的很幸运...
猜你喜欢

org.apache.ibatis.binding.BindingException Invalidbound statement (not found)的解决方案和造成原因分析(超详细)

How to choose a truly "easy-to-use, high-performance" remote control software

Do you agree with this view?Most businesses are digitizing just to ease anxiety

新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!

Mysql环境变量的配置(详细图解)

同样做软件测试,和月收入 3W 的学弟聊了一晚上,我彻底崩溃了

使用较广泛的安全测试工具有哪些?

Shell脚本实现多选DNS同时批量解析域名IP地址(新更新)

你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑

DVWA Clearance Log 2 - Command Injection
随机推荐
循环语句综合练习
npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
games202:三,实时环境光照IBL + PRT
R语言ggplot2可视化:使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用tbody_add_border为表格中的表头添加外侧框线
读博一年后对机器学习工程的思考
Oracle超全SQL,细节狂魔
LayaBox---TypeScript---Module Analysis
关于#oracle#的问题,如何解决?
从零开始Blazor Server(5)--权限验证
【术语科普】关于集成工作台那些难懂的词儿,看这篇秒懂!
你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
wireshark的安装教程(暖气片安装方法图解)
Shell script realizes multi-select DNS simultaneous batch resolution of domain name IP addresses (new update)
LayaBox---TypeScript---JSX
未知内容监控
基于列表的排队与叫号系统
38岁女儿不恋爱没有稳定工作老母亲愁哭
如何安装dosbox(pycharm详细安装教程)
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
阿里云数据存储生态计划发布,助力伙伴数据创新