当前位置:网站首页>Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue
Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue
2022-08-02 10:40: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(); */
边栏推荐
- 小几届的学弟问我,软件测试岗是选11k的华为还是20k的小公司,我直呼受不了,太凡尔赛了~
- Unknown content monitoring
- Hongxing, donate another million
- 字节跳动软件测试岗,收到offer后我却拒绝了~给面试的人一些忠告....
- LayaBox---TypeScript---Module Analysis
- C#/VB.NET 添加多行多列图片水印到Word文档
- npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
- Event object, do you know it well?
- R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化、使用diff函数计算对数化后的时间序列数据的逐次差分(计算价格的对数差分)
- MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
猜你喜欢
随机推荐
众城优选系统开发功能
R language ggplot2 visualization: use the ggbarplot function of the ggpubr package to visualize the horizontal column chart (bar chart), use the orientation parameter to set the column chart to be tra
21年毕业转行软件测试,从0收入到月薪过万,我真的很幸运...
SVN如何删除文件名包含空格的文件
情景剧《重走长征路》上演
MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
MSYS2 QtCreator Clangd code analysis can not find mm_malloc.h problem remedy
Oracle查询提示 ORA-00933 SQL command not properly ended 原因排查
学习笔记-支付宝支付
idea常用插件
利用二维数据学习纹理三维网格生成(CVPR 2020)
Rear tube implements breadcrumb function
logo 图标(php图片加文字水印)
Com多进程通信实现
List-based queuing and calling system
Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
神通数据库,批量插入数据的时候失败
小几届的学弟问我,软件测试岗是选11k的华为还是20k的小公司,我直呼受不了,太凡尔赛了~
sqlmap安装教程用w+r打开(sqlyog安装步骤)
LayaBox---TypeScript---三斜线指令









![ASP.NET Core 6框架揭秘实例演示[31]:路由"高阶"用法](/img/57/821576ac28abc8d1c0d65df6a72fa3.png)