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(); 这样就可以很好的解释哪些全局变量 ...
随机推荐
- poj3335
半平面交&多边形内核.因为没注意了点的情况自闭了. https://blog.csdn.net/qq_40861916/article/details/83541403 这个说的贼好. 多边形 ...
- Nestjs 接口验证
class-validator Nestjs yarn add class-transformer class-validator main.ts import { NestFactory } fro ...
- java个人博客源码
初入博客园,请各位多关照,来而不往非礼也. 如需要源码以及学习内容,qq:1397617269,我看到就回你们资源. 直接给链接: 链接:https://pan.baidu.com/s/1S_awtg ...
- js的简单介绍
1.js的介绍 js全称叫javascript,但不是java,他是一门前台语言,而java是后台语言. js的作者是布兰登艾奇. 前台语言:运行在客户端的 后台语言:跟数据库有关的. 2.能干什么? ...
- Python学习之旅(一)
Python的简介 Python是一种面向对象的.动态的脚本语言,可用来设计网页和开发后台功能.其创始人Guido van Rossum于1989年圣诞节期间创造了这门语言. (图片来自百度) Pyt ...
- 在IOS应用中打开另外一个应用的解决方案
最近要在IOS中实现一个应用启动另外一个应用的功能,搜了一些资料,使用UIApplication的openURL:的方法就能实现,现在整理和大家分享一下! 注册自定义URL协议 首先被启动的应用需要向 ...
- [转载] apache ab压力测试报错(apr_socket_recv: Connection reset by peer (104))
遇见相同的问题. https://www.cnblogs.com/felixzh/p/8295471.html -------------------------------------------- ...
- 从光盘安装ubuntu系统
参考博客: https://www.jianshu.com/p/7929e4911206
- 网络视频播放ZFPlayer
根据项目需要,公司app需要用到视频播放功能,推荐ZFPlayer,视频播放几乎有你想要的任何样式,该博客只是为了给自己留一个以后查找的资料, 改代码可以使用ZFPlayer github地址 htt ...
- JAVA微信公众号网页开发 —— 接收微信服务器发送的消息
WeixinMessage.java package com.test; import java.io.Serializable; /** * This is an object that conta ...