当前位置:网站首页>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(); */
边栏推荐
- windbg分析进程卡死
- MySql模糊查询大全
- Oracle超全SQL,细节狂魔
- currentstyle 织梦_dede currentstyle属性完美解决方案
- MySQL百万数据优化总结 一
- 循环结构--while循环
- 阿里云数据存储生态计划发布,助力伙伴数据创新
- The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
- 阿里CTO程立:阿里巴巴开源的历程、理念和实践
- LayaBox---TypeScript---命名空间和模块
猜你喜欢

【面向校招】Golang面试题合集

为什么要使用BGP?

yolov7创新点

LeetCode每日一练 —— 20. 有效的括号

Turning and anti-climbing attack and defense

Verilog's random number system task----$random

5G基础学习1、5G网络架构、网络接口及协议栈

The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit

多线程(基础) - 4万字总结

You Only Hypothesize Once: 用旋转等变描述子估计变换做点云配准(已开源)
随机推荐
LayaBox---TypeScript---模块
Jay Chou's new song is released, crawl the "Mojito" MV barrage, and see what the fans have to say!
Verilog's random number system task----$random
Verilog的随机数系统任务----$random
链表的实现
LeetCode每日一练 —— 20. 有效的括号
Spearman's correlation coefficient
R语言使用zoo包中的rollapply函数以滚动的方式、窗口移动的方式将指定函数应用于时间序列、设置align参数指定结果数据中的时间标签取自窗口中的位置(参数right指定取自窗口的最右侧)
保姆级教程:写出自己的移动应用和小程序(篇二)
利用二维数据学习纹理三维网格生成(CVPR 2020)
Event 对象,你很了解吗?
Mysql环境变量的配置(详细图解)
Long battery life or safer?Seal and dark blue SL03 comparison shopping guide
软件测试的基本理论知识(软件测试面试基础知识)
MySql模糊查询大全
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化、使用diff函数计算对数化后的时间序列数据的逐次差分(计算价格的对数差分)
Turning and anti-climbing attack and defense
SVN如何删除文件名包含空格的文件
字节跳动软件测试岗,收到offer后我却拒绝了~给面试的人一些忠告....
LayaBox---TypeScript---迭代器和生成器