622 CircularQueue C#
public class MyCircularQueue {
int[] Queue=null;
int _Front = 0;
int _Rear = 0;
int Length = 0;
int Count = 0;
/** Initialize your data structure here. Set the size of the queue to be k. */
public MyCircularQueue(int k) {
Queue = new int[k];
_Front = 0;
_Rear = 0;
Count = 0;
Length = k;
}
/** Insert an element into the circular queue. Return true if the operation is successful. */
public bool EnQueue(int value) {
if(IsFull())
return false;
Queue[_Rear] = value;
_Rear++;
_Rear = _Rear % Length;
Count++;
return true;
}
/** Delete an element from the circular queue. Return true if the operation is successful. */
public bool DeQueue() {
if(IsEmpty())
return false;
_Front++;
_Front = _Front % Length;
Count--;
return true;
}
/** Get the front item from the queue. */
public int Front() {
if(IsEmpty())
return -1;
return Queue[_Front];
}
/** Get the last item from the queue. */
public int Rear() {
if(IsEmpty())
return -1;
int rear = _Rear - 1;
if(rear == -1)
rear = rear+Length;
return Queue[rear];
}
/** Checks whether the circular queue is empty or not. */
public bool IsEmpty() {
if(Count == 0)
return true;
return false;
}
/** Checks whether the circular queue is full or not. */
public bool IsFull() {
if(Count == Length)
return true;
return false;
}
}
/**
* 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();
*/
622 CircularQueue C#的更多相关文章
- LeetCode 622:设计循环队列 Design Circular Queue
LeetCode 622:设计循环队列 Design Circular Queue 首先来看看队列这种数据结构: 队列:先入先出的数据结构 在 FIFO 数据结构中,将首先处理添加到队列中的第一个元素 ...
- Java实现 LeetCode 622 设计循环队列(暴力大法)
622. 设计循环队列 设计你的循环队列实现. 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环.它也被称为"环形缓冲器" ...
- 622.设计循环队列 javascript实现
设计你的循环队列实现. 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环.它也被称为“环形缓冲器”. 循环队列的一个好处是我们可以利用这个队列 ...
- Codeforces 622 F. The Sum of the k-th Powers
\(>Codeforces \space 622\ F. The\ Sum\ of\ the\ k-th\ Powers<\) 题目大意 : 给出 \(n, k\),求 \(\sum_{i ...
- 【DFS】Paintball(6-22)
[UVA11853]Paintball 算法入门经典第6章6-22(P175) 题目大意:有一个1000*1000的正方形战场,西南角坐标(0,0),西北角坐标(0,1000),有n个敌人,每个敌人处 ...
- LeetCode 622——设计循环队列
1. 题目 设计你的循环队列实现. 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环.它也被称为"环形缓冲器". 循环队列 ...
- RQNOJ 622 最小重量机器设计问题:dp
题目链接:https://www.rqnoj.cn/problem/622 题意: 一个机器由n个部件组成,每一种部件都可以从m个不同的供应商处购得. w[i][j]是从供应商j处购得的部件i的重量, ...
- CF 622 F The Sum of the k-th Powers —— 拉格朗日插值
题目:http://codeforces.com/contest/622/problem/F 设 f(x) = 1^k + 2^k + ... + n^k 则 f(x) - f(x-1) = x^k ...
- php课程 6-22 字符串格式化函数有哪些(精问)
php课程 6-22 字符串格式化函数有哪些(精问) 一.总结 一句话总结: 1.猜测一下$_GET()怎么来的? 函数赋值给变量的操作:$_YZM=get(); 这样就可以很好的解释哪些全局变量 ...
随机推荐
- 添加ll命令
$ vim ~/.bashrcalias ll='ls -l' #加入此行 ps:加入后肯能无法当场起作用,执行该句: source ~/.bashrc
- .Net逆向初学习
前一段时间逆向一个程序时发现是.net的,然后用OD和IDA都调试不了,最后上网查了一下原来.net的逆向要用专门的工具.这里推荐大家一篇文章去了解一下逆向.net的一些工具简介:http://www ...
- HashSet的底层
今天看博客,发现有个哥哥写到 HashSet的底层是数组结构,有点懵逼,不是HashMap吗怎么成数组了? 遂去查了下源码: 得以下结论: HashSet底层是 HashMap,其元素是内部map的k ...
- F#周报2019年第2期
新闻 Rider上的拼写助手,对未使用引用的代码分析及更多F#相关特性的更新 .NET开源革命开始 ML.NET 0.9发布记录 测试驱动的集成开发环境 Giraffe在GitHub上超过了1000个 ...
- 关于vue执行打包后,如何在本地浏览问题
最近一个人在捣鼓vue,写完项目后发现在npm run dev下可以正常访问,bulid之后却一片空白,查看console出现许多Failed to load resource: net::ERR_F ...
- asp.net NPOI导出xlsx格式文件,打开文件报“Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃”
NPOI导出xlsx格式文件,会出现如下情况: 点击“是”: 导出代码如下: /// <summary> /// 将datatable数据写入excel并下载 /// </summa ...
- 11.0-uC/OS-III就绪列表(优先级)
准备运行的任务被放置于就绪列表中.就绪列表包括2个部分:位映像组包含了优先级信息,一个表包含了所有指向就绪任务的指针. 1.优先级 图6-1到6-3显示了优先级的位映像组.它的宽度取决于CPU_DAT ...
- C++提供的四种新式转换--const_cast dynamic_cast reinterpret_cast static_cast
关于强制类型转换的问题,许多书都讨论过,写的最具体的是C++之父的<C++的设计和演化>. 最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_c ...
- openshift 容器云从入门到崩溃之十《容器监控-数据展示》
POD资源历史曲线(CPU.内存.网络) 监控方案heapster+hawkular-metrics+hawkular-cassandra heapster负责收集数据 hawkular-cassan ...
- react native出现 undefined is not a function_this4.错误函数无法识别
该函数可能里可能有this,的上个函数this要绑定bind(this)