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(); 这样就可以很好的解释哪些全局变量 ...
随机推荐
- linux安装jdk和tomcat命令
1.linux centos6.5 安装jdk1.在/usr/local/src目录下,创建java文件夹,拷贝jdk安装包到/usr/local/src/java下面:cd /usr/local/s ...
- CXF整合Sping与Web容器
1.创建HelloWorld 接口类 package com.googlecode.garbagecan.cxfstudy.helloworld; import javax.jws.WebMethod ...
- mac重启,开启apache时报错~~~镜像没有找到
mac重启apache时,报类似下面的错 dyld: Library not loaded: /usr/local/lib/libjpeg8.dylib Referenced from: /usr/l ...
- 1.7Oob 方法重载和成员变量,局部变量,构造方法
1:方法调用,如果值有参方法,必须传递实际参数. 2:方法定义了多少个参数,传递的实际参数就 必须有多少个, 方法的作用:1:描述某个类的作用,2:软件的复用 这个复用率低,作用小,价值很低: 3:
- MVCC&PURGE&分布式事务
Ⅰ.MVCC介绍 consistent non-locking read,通过行多版本控制的方式读取当前执行时间点的记录 默认情况下innodb select没有任何锁,读到的记录在更新就通过undo ...
- 前端JavaScript获取时间戳
/** * 获取时间戳 * @param {*长度} len */ export function getTimestamp(len=) { var tmp = Date.parse( new Dat ...
- Restful API设计规范
理解RESTful架构 Restful API设计指南 理解RESTful架构 越来越多的人开始意识到,网站即软件,而且是一种新型的软件. 这种"互联网软件"采用客户端/服务器模式 ...
- 前端的重要部分js
js用来实现页面的动态效果. js的特点:1.是客户端语言,客户端进行解释执行. 2.是一种脚本语言 3.是一种基于对象的语言,不用定义类和实例化对象,直接使用类即可 4.js前端和后端都可以做 js ...
- poi导入excel表格数据到数据库的时候,对出生日期的校验
出生日期格式为8位数字的字符串 如:yyyyMMdd 规则:yyyy大于1900并小于当前时间,月.日 按日期规则校验 //解决读过来的字符串显示为科学计数法问题 BigDecimal bd = ne ...
- Cartographer源码阅读(4):Node和MapBuilder对象2
MapBuilder的成员变量sensor::Collator sensor_collator_; 再次阅读MapBuilder::AddTrajectoryBuilder方法.首先构造了mappin ...