当前位置:网站首页>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(); */
边栏推荐
- 3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
- 循环结构--while循环
- R语言ggplot2可视化:使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、使用tbody_add_border为表格中的表头添加外侧框线
- 从零开始Blazor Server(5)--权限验证
- 阿里巴巴 CTO 程立:开源是基础软件的源头!
- Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
- npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
- 有奖征集|TaoCloud&宝德联合举办全闪POC!
- 初探zend引擎
- 神通数据库,批量插入数据的时候失败
猜你喜欢
利用二维数据学习纹理三维网格生成(CVPR 2020)
软件工程国考总结——选择题
Alibaba CTO Cheng Li: Alibaba Open Source History, Concept and Practice
从众多接口中脱颖而出的最稳定的接口——淘宝详情api
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
博云入选Gartner中国DevOps代表厂商
神通数据库,批量插入数据的时候失败
You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
链表的实现
随机推荐
The ggbarplot function of the R language ggpubr package visualizes the grouped histogram, sets the add parameter to mean_se to visualize the histogram of the mean values of different levels and adds
Spearman's correlation coefficient
3D激光slam:LeGO-LOAM---地面点提取方法及代码分析
开源一夏 | GO语言框架中如何快速集成日志模块
LayaBox---TypeScript---JSX
DirectX修复工具增强版「建议收藏」
Event 对象,你很了解吗?
Event object, do you know it well?
MySql模糊查询大全
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the stacked bar plot, the lab.pos parameter specifies the position of the numerical label of the bar cha
R语言ggpubr包的ggbarplot函数可视化分组柱状图、设置add参数为mean_se可视化不同水平均值的柱状图并为柱状图添加误差线(se标准误差)、position参数自定义分组柱状图分离
5G基础学习1、5G网络架构、网络接口及协议栈
详细总结SoC、DSP、MCU、GPU和FPGA等基础概念
yolov7 innovation point
MySQL百万数据优化总结 一
如何封装微信小程序的 wx.request() 请求
同样做软件测试,和月收入 3W 的学弟聊了一晚上,我彻底崩溃了
行为型模式-模板方法模式
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
太帅了!我用炫酷大屏展示爬虫数据!