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(); 这样就可以很好的解释哪些全局变量 ...
随机推荐
- PHP实现今天是星期几
echo "今天是星期" . mb_substr( "日一二三四五六",date("w"),1,"utf-8" );
- linux 的基本操作(linux系统的日常管理)
系统的日常管理 笔者在前面介绍的内容都为linux系统基础类的,如果你现在把前面的内容全部很好的掌握了,那最好了.不过笔者要说的是,即使你完全掌握了,你现在还是不能作为一名合格的linux系统管理员的 ...
- string find_last_of 用法
int find_first_of(char c, int start = 0): 查找字符串中第1个出现的c,由位置start开始. 如果有匹配, ...
- python中matplotlib的颜色及线条控制
参考网址: http://www.cnblogs.com/darkknightzh/p/6117528.html http://stackoverflow.com/questions/22408237 ...
- vim创建程序文件自动添加头部注释/自动文件头注释与模板定义
Vim 自动文件头注释与模板定义 在vim的配置文件.vimrc添加一些配置可以实现创建新文件时自动添加文件头注释,输入特定命令可以生成模板. 使用方法 插入模式输入模式输入seqlogic[Ente ...
- 15.3-uC/OS-III资源管理(多值信号量)
多值信号量是 uC/OS 操作系统的一个内核对象, 主要用于标志事件的发生和共享资源管理. 1.如果想要使用多值信号量,就必须事先使能多值信号量. 多值信号量的使能位于“os_cfg.h”. 2.OS ...
- [LeetCode] 62. Unique Paths_ Medium tag: Dynamic Programming
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...
- DTCC2019第十届中国数据库技术大会将于5月在北京召开
作为国内顶级的数据领域技术盛会,10年来,DTCC见证了国内数据库技术的迅猛发展,各种分布式数据库.NoSQL.NewSQL技术异军突起,与Oracle.DB2等分庭抗礼,甚至大有超越之势.在这种背景 ...
- 57.搭建Vue环境
nodejs官网http://nodejs.cn/下载安装包,无特殊要求可本地傻瓜式安装,这里选择2017-5-2发布的 v6.10.3 cmd命令行: node -v //显示node版本 v6.1 ...
- input[type = 'date']标签。
1.首先调用浏览器自带时间控件,input的type属性有以下几种写法: type=’date’ //显示年.月.日 type=‘month’//显示年.月 type=‘week’//显示年.周 ty ...