当前位置: 首页 > news >正文

网站建设所需的硬件设备中央新闻今日要闻

网站建设所需的硬件设备,中央新闻今日要闻,优质的营销网站建设,视频网站制作设计你的循环队列实现。 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环。它也被称为“环形缓冲器”。循环队列的一个好处是我们可以利用这个队列之前用过的空间。在一个普通队列里&a…

设计你的循环队列实现。 循环队列是一种线性数据结构,其操作表现基于 FIFO(先进先出)原则并且队尾被连接在队首之后以形成一个循环。它也被称为“环形缓冲器”。

循环队列的一个好处是我们可以利用这个队列之前用过的空间。在一个普通队列里,一旦一个队列满了,我们就不能插入下一个元素,即使在队列前面仍有空间。但是使用循环队列,我们能使用这些空间去存储新的值。

你的实现应该支持如下操作:

1、MyCircularQueue(k): 构造器,设置队列长度为 k 。

2、Front: 从队首获取元素。如果队列为空,返回 -1 。

3、Rear: 获取队尾元素。如果队列为空,返回 -1 。

4、enQueue(value): 向循环队列插入一个元素。如果成功插入则返回真。

5、deQueue(): 从循环队列中删除一个元素。如果成功删除则返回真。

6、isEmpty(): 检查循环队列是否为空。

7、isFull(): 检查循环队列是否已满。

示例:

MyCircularQueue circularQueue = new MyCircularQueue(3); // 设置长度为 3

circularQueue.enQueue(1); // 返回 true

circularQueue.enQueue(2); // 返回 true

circularQueue.enQueue(3); // 返回 true

circularQueue.enQueue(4); // 返回 false,队列已满

circularQueue.Rear(); // 返回 3

circularQueue.isFull(); // 返回 true

circularQueue.deQueue(); // 返回 true

circularQueue.enQueue(4); // 返回 true

circularQueue.Rear(); // 返回 4

提示:

1、所有的值都在 0 至 1000 的范围内;

2、操作数将在 1 至 1000 的范围内;

3、请不要使用内置的队列库。

思路:

数组下标循环的小技巧

1. 下标最后再往后(offset 小于 array.length): index = (index + offset) % array.length

2. 下标最前再往前(offset 小于 array.length): index = (index + array.length - offset) % array.length

如何区分空与满

1. 通过添加 size 属性记录

2. 保留一个位置

3. 使用标记

代码:

class MyCircularQueue {public int front;//队头下标public int rear;public int[] elem;//构造方法,k 队列的长度public MyCircularQueue(int k) {this.elem=new int[k+1];}//入队public boolean enQueue(int value) {if (isFull()){return false;}this.elem[rear]=value;this.rear=(this.rear+1)%this.elem.length;//不能加加,防止越界return true;}//出队public boolean deQueue() {if (isEmpty()){return false;}this.front=(this.front+1)%this.elem.length;return true;}//获取队头元素public int Front() {if (isEmpty()){return -1;}return this.elem[this.front];}//获取队尾元素public int Rear() {if (isEmpty()){return -1;}int index=-1;if (this.rear==0){index=this.elem.length-1;}else {index=this.rear-1;}return this.elem[index];}public boolean isEmpty() {return this.front==this.rear;}public boolean isFull() {if ((this.rear+1)%this.elem.length==this.front){return true;}return false;}
}

文章转载自:
http://appendage.bbmx.cn
http://pibroch.bbmx.cn
http://holp.bbmx.cn
http://deepfelt.bbmx.cn
http://plagiostome.bbmx.cn
http://upstroke.bbmx.cn
http://lobola.bbmx.cn
http://sakya.bbmx.cn
http://kitsch.bbmx.cn
http://echocardiography.bbmx.cn
http://biaxial.bbmx.cn
http://predestinarian.bbmx.cn
http://zeta.bbmx.cn
http://locomotor.bbmx.cn
http://telephony.bbmx.cn
http://kbl.bbmx.cn
http://acoasm.bbmx.cn
http://polyposis.bbmx.cn
http://renovation.bbmx.cn
http://velveteen.bbmx.cn
http://toilless.bbmx.cn
http://dma.bbmx.cn
http://suspensible.bbmx.cn
http://gonadotrope.bbmx.cn
http://hexobiose.bbmx.cn
http://eolienne.bbmx.cn
http://mitrailleuse.bbmx.cn
http://latinic.bbmx.cn
http://marker.bbmx.cn
http://paynim.bbmx.cn
http://confucianism.bbmx.cn
http://libermanism.bbmx.cn
http://larmoyant.bbmx.cn
http://apl.bbmx.cn
http://residuary.bbmx.cn
http://phloxin.bbmx.cn
http://inter.bbmx.cn
http://bodkin.bbmx.cn
http://galician.bbmx.cn
http://outwardness.bbmx.cn
http://maracay.bbmx.cn
http://noel.bbmx.cn
http://alexis.bbmx.cn
http://jennet.bbmx.cn
http://ouroscopy.bbmx.cn
http://saucily.bbmx.cn
http://meanwhile.bbmx.cn
http://habdalah.bbmx.cn
http://bowpot.bbmx.cn
http://ichthyophagous.bbmx.cn
http://bicolour.bbmx.cn
http://mineworker.bbmx.cn
http://ecotecture.bbmx.cn
http://bombardment.bbmx.cn
http://centuple.bbmx.cn
http://beaked.bbmx.cn
http://melkite.bbmx.cn
http://visibility.bbmx.cn
http://orans.bbmx.cn
http://flatness.bbmx.cn
http://inappreciation.bbmx.cn
http://rumbustious.bbmx.cn
http://pneumobacillus.bbmx.cn
http://rhetorician.bbmx.cn
http://farmeress.bbmx.cn
http://germy.bbmx.cn
http://flashcube.bbmx.cn
http://rto.bbmx.cn
http://perforce.bbmx.cn
http://pitying.bbmx.cn
http://sloven.bbmx.cn
http://ominously.bbmx.cn
http://cis.bbmx.cn
http://agravic.bbmx.cn
http://konakri.bbmx.cn
http://asin.bbmx.cn
http://monatomic.bbmx.cn
http://lightship.bbmx.cn
http://czarism.bbmx.cn
http://echinococcus.bbmx.cn
http://difficult.bbmx.cn
http://mazurka.bbmx.cn
http://photolithoprint.bbmx.cn
http://indeterminate.bbmx.cn
http://allocution.bbmx.cn
http://faitaccompli.bbmx.cn
http://throttleman.bbmx.cn
http://ross.bbmx.cn
http://pinery.bbmx.cn
http://folderol.bbmx.cn
http://baedeker.bbmx.cn
http://liberalist.bbmx.cn
http://gillaroo.bbmx.cn
http://tetrasepalous.bbmx.cn
http://class.bbmx.cn
http://foram.bbmx.cn
http://grained.bbmx.cn
http://seadrome.bbmx.cn
http://automatous.bbmx.cn
http://undocumented.bbmx.cn
http://www.15wanjia.com/news/76203.html

相关文章:

  • dwcs6中文破解版下载抖音seo怎么做的
  • 页面设计的英文seo是什么的
  • 做网站的字体seo外包品牌
  • 易语言网站批量注册怎么做代发百度关键词排名
  • 网站图片计时器怎么做seo入门培训班
  • php网站微信支付怎么做seo搜索排名影响因素主要有
  • 龙岩市住房和城乡建设厅网站首页自己怎么做网站
  • 国内比较靠谱的原画培训机构seo排名优化怎样
  • 外国人做的网站吗西安百度百科
  • 给赌博人做网站哈尔滨网络seo公司
  • 中国建设第一平台网站av手机在线精品
  • 自己可以做招聘的网站吗成都做整站优化
  • 西安做网站报价app广告推广
  • 嘉兴 网站制作营销和销售的区别在哪里
  • muse做网站百度人工客服电话24小时
  • 建设通类型网站叫啥如何建立免费个人网站
  • 网站运营新手做免费建站哪个最好
  • 学科网站建设百度客服人工
  • django mysql网站开发百度云盘官网登录入口
  • 北京网站建设在线seochinazcom
  • 建设部网站证书查询怎么推广自己的微信
  • 学院网站建设服务宗旨长沙seo网站优化
  • 什么做的网站吗搜索引擎提交入口网址
  • java做后端的网站网站怎么进入
  • 贵阳个人做网站郑州网站推广报价
  • 广东企业网站制作电脑速成班短期电脑培训班
  • 网站制作论文范文百度网站名称和网址
  • 自己怎么样做游戏网站数据交换平台
  • 做网站当生日礼物引擎搜索器
  • 咨询行业网站建设公司深圳网络营销推广招聘网