当前位置:网站首页>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(); */
边栏推荐
- Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
- Com多进程通信实现
- LayaBox---TypeScript---Symbols
- LayaBox---TypeScript---三斜线指令
- 如何在技术上来保证LED显示屏质量?
- sqlmap安装教程用w+r打开(sqlyog安装步骤)
- 小几届的学弟问我,软件测试岗是选11k的华为还是20k的小公司,我直呼受不了,太凡尔赛了~
- 软件工程国考总结——选择题
- qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
- SVN如何删除文件名包含空格的文件
猜你喜欢
随机推荐
从零开始Blazor Server(5)--权限验证
sqlmap安装教程用w+r打开(sqlyog安装步骤)
Hello, my new name is "Bronze Lock/Tongsuo"
博云入选Gartner中国DevOps代表厂商
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data
MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
8年软件测试工程师的感悟:与薪资相匹配的永远是实力
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
R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
MSYS2 QtCreator Clangd code analysis can not find mm_malloc.h problem remedy
wireshark的安装教程(暖气片安装方法图解)
Do you agree with this view?Most businesses are digitizing just to ease anxiety
armv7与armv8的区别(v8和w12的区别)
windbg分析进程卡死
身为程序猿——谷歌浏览器的这些骚操作你真的废吗!【熬夜整理&建议收藏】[通俗易懂]
3年测试在职,月薪还不足2w,最近被裁员,用亲身经历给大家提个醒...
WPF 截图控件之文字(七)「仿微信」
Linux system uninstall, install, upgrade, migrate clickHouse database
学习笔记-支付宝支付
一款优秀的中文识别库——ocr