当前位置:网站首页>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(); */
边栏推荐
- Jay Chou's new song is released, crawl the "Mojito" MV barrage, and see what the fans have to say!
- 3 d laser slam: LeGO - LOAM - ground point extracting method and the analysis of the code
- iNFTnews | Seeing the two sides of the metaverse, what is the true Internet and the Internet of value?
- 情景剧《重走长征路》上演
- yolov7创新点
- R language ggplot2 visualization: based on the fill parameter and shape parameter in the aes function, custom draw a grouped line chart and add data points (scatter points), use the legend.position fu
- TimerTask(addin timer语音)
- 从测试入门到测试架构师,这10年,他是这样让自己成才的
- The 38-year-old daughter is not in love and has no stable job, the old mother is crying
- Hongxing, donate another million
猜你喜欢
随机推荐
Unknown content monitoring
如何安装dosbox(pycharm详细安装教程)
阿里云数据存储生态计划发布,助力伙伴数据创新
MSYS2 QtCreator Clangd 代码分析找不到 mm_malloc.h的问题补救
games202:三,实时环境光照IBL + PRT
R language time series data arithmetic operation: use the log function to log the time series data, and use the diff function to calculate the successive difference of the logarithmic time series data
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
LayaBox---TypeScript---装饰器
情景剧《重走长征路》上演
软件工程国考总结——选择题
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
The ggbarplot function of the R language ggpubr package visualizes the grouped histogram, sets the add parameter to mean_se to visualize the histogram of the mean values of different levels and adds
保姆级教程:写出自己的移动应用和小程序(篇二)
C#/VB.NET 添加多行多列图片水印到Word文档
神通数据库,批量插入数据的时候失败
Why use BGP?
LayaBox---TypeScript---Module Analysis
从众多接口中脱颖而出的最稳定的接口——淘宝详情api
The R language uses the ggtexttable function of the ggpubr package to visualize the table data (draw the table directly or add the table data to the image), set the theme parameter to customize the fi
[Science of Terminology] For those difficult words about the integrated workbench, read this article to understand in seconds!









