当前位置:网站首页>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(); */
边栏推荐
- Linux系统卸载,安装,升级,迁移clickHouse数据库
- 循环结构--do-while循环
- LayaBox---TypeScript---高级类型
- R语言ggpubr包的ggline函数可视化分组折线图、add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图、自定义palette设置颜色
- yolov7创新点
- org.apache.ibatis.binding.BindingException Invalidbound statement (not found)的解决方案和造成原因分析(超详细)
- 未知内容监控
- 如何选择一块真正“好用的、性能高”的远程控制软件
- LayaBox---TypeScript---命名空间和模块
- 你认同这个观点吗?大多数企业的数字化都只是为了缓解焦虑
猜你喜欢
随机推荐
qq邮箱日发5万邮件群发技术(qq邮箱怎样定时发送邮件)
如何搭建威纶通触摸屏与S7-200smart之间无线PPI通信?
日元疲软令游戏机在日本变身“理财产品”:黄牛大赚
Turning and anti-climbing attack and defense
LayaBox---TypeScript---Decorator
MySql模糊查询大全
5G基础学习1、5G网络架构、网络接口及协议栈
Weak yen turns game consoles into "financial products" in Japan: scalpers make big profits
Hongxing, donate another million
Event object, do you know it well?
Smoothing of time series data in R language: smoothing time series data to remove noise using the dpill function and locpoly function of the KernSmooth package
WPF 截图控件之文字(七)「仿微信」
3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
初探zend引擎
程序员的浪漫七夕
R语言使用zoo包中的rollapply函数以滚动的方式、窗口移动的方式将指定函数应用于时间序列、设置align参数指定结果数据中的时间标签取自窗口中的位置(参数right指定取自窗口的最右侧)
windbg分析进程卡死
Verilog的随机数系统任务----$random
MySql tens of millions of paging optimization, fast insertion method of tens of millions of data




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


