当前位置:网站首页>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(); */
边栏推荐
猜你喜欢

基于列表的排队与叫号系统

神通数据库,批量插入数据的时候失败

The realization of the list

软件测试岗位巨坑?阿里在职7年测试人告诉你千万别上当

读博一年后对机器学习工程的思考

Mysql环境变量的配置(详细图解)

Verilog的随机数系统任务----$random

Do you agree with this view?Most businesses are digitizing just to ease anxiety

iNFTnews | 看见元宇宙的两面,何谓全真互联网和价值互联网?

周鸿祎称微软抄袭 360 安全模式后发文否认;英特尔CEO基辛格回应市值被AMD超越:股价下跌是咎由自取|极客头条...
随机推荐
R语言时间序列数据算术运算:使用log函数将时间序列数据的数值对数化、使用diff函数计算对数化后的时间序列数据的逐次差分(计算价格的对数差分)
众城优选系统开发功能
The heavyweights are coming!Spoilers for the highlights of the Alibaba Cloud Life Science and Intelligent Computing Summit
After 21 years of graduation, I switched to software testing. From 0 income to a monthly salary of over 10,000, I am really lucky...
c#反射和特性
行为型模式-策略模式
LayaBox---TypeScript---Three slash instructions
R语言使用zoo包中的rollapply函数以滚动的方式、窗口移动的方式将指定函数应用于时间序列、设置align参数指定结果数据中的时间标签取自窗口中的位置(参数right指定取自窗口的最右侧)
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
MySQL百万数据优化总结 一
同样做软件测试,和月收入 3W 的学弟聊了一晚上,我彻底崩溃了
初探zend引擎
后管实现面包屑功能
npm ERR! 400 Bad Request - PUT xxx - Cannot publish over previously published version “1.0.0“.
新“内卷”席卷科技圈,Google CEO 要求 174000 员工提高工作效率!
DVWA Clearance Log 2 - Command Injection
重磅大咖来袭!阿里云生命科学与智能计算峰会精彩内容剧透
R语言使用ggpubr包的ggtexttable函数可视化表格数据(直接绘制表格图或者在图像中添加表格数据)、设置theme主题参数自定义表格中表头内容的填充色(使用colnames.style参数)
博云入选Gartner中国DevOps代表厂商
The R language uses the rollapply function in the zoo package to apply the specified function to the time series in a rolling manner and the window moves, and set the align parameter to specify that t