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

兰州建网站今日热点新闻头条排行榜

兰州建网站,今日热点新闻头条排行榜,农村网站建设调查报告,做外贸网站挣钱吗1.题目的初步分析 我们分析上述题目的时候会发现题目非常的长,不好整理思路,我这里可以大致的将本题的几个核心点说出来: 1.队列的思路 循环队列说来说去不还是队列嘛,那么队列的基本操作增删查改、以及队列的基本结构肯定都是不能…

1.题目的初步分析

我们分析上述题目的时候会发现题目非常的长,不好整理思路,我这里可以大致的将本题的几个核心点说出来:

1.队列的思路

循环队列说来说去不还是队列嘛,那么队列的基本操作增删查改、以及队列的基本结构肯定都是不能变的,我们知道队列的逻辑结构就是先进先出,而在C语言中,我们要实现队列可以采用两种方法,一种是链表,一种是顺序表,本题我们采用顺序表。

2.循环的实现

本题我们既然采用顺序表的结构来实现这个循环队列,那么我们就必须想一种方法来让它实现逻辑上的循环,这里可以提供一个思路,多开辟一块空间,队头指针指向队列首元素,队尾指针指向队尾元素的下一个空间;

比如上诉图,假设题目要求k为3,那么我们就开四块空间,为什么我们一定要多开一个空间呢?这是为了我们应对队列里只有0个元素或满元素的时候,倘若我们rear指向的是最后一个元素,那么我们0个元素和满元素就没有办法判断了,因为这两种情况front都等于n。

2.具体实现

2.1结构体里的结构

arr里面就是我们的元素了,k代表有k个元素,front就是首元素的下标,rear就是尾元素的下一个空间的下标。

2.2创建结构体

创建的步骤顺序表类似,注意这里要返回一个结构体类型类型的指针,所以我们就创建一个结构体指针的变量,创建完后就该给结构体里的arr数组开辟空间了,注意我们这里是开辟k+1个空间。然后就是把k赋值给结构体里的k,把front和rear都初始化为0,再返回这个指针变量就可以了。

2.3判空

注意,原本题目中的判空是在下面的位置,但我们把它提到前面来是因为在实现其它接口的时候判空和判满能给我们很大的帮助,所以我们待会也要把判满的接口提到上面来。

判空的实现非常简单,只需要判断rear和front是否相等就可以了,因为rear指向的是尾元素的下一个,所以逻辑上如果满的话,rear会呆在尾元素和头元素之间的空空间上,这也就说明了只有0个元素这种情况会使front等于rear。

2.4判满

为什么要这样来判满呢?因为逻辑上来说,既然是一个循环,那么满元素的时候rear就会在front的前面一个,但物理结构上我们实现的方式就是%,

比如说这种情况,k为3,rear也是3,,3%3=0,0=front,这样就达到判满的效果,那么为什么我们要加1呢,这是因为倘若我们的rear为0,那么0%任何数都是0,为了避免这种情况,我们才在两边都加上1。

2.5插入

插入操作我们先判满,如果队列满了我们就返回假,如果队列不为满,我们就赋值,赋完之后我们就给rear加上1,因为我们rear指向的是尾元素的下一个,但是不要忘记了,rear可能会超出范围,所以我们可以取余,倘若这一次加1操作超出了范围,我们就%(k+1),还是上面那幅图,倘若rear为四,k+1也为4,因为,下标本来就比元素个数少1嘛,所以这样操作之后,我们就让rear重新回到了0的位置,也就构成了物理意义上的循环,然后我们还要返回真。

注意,接口是有独立性的,我们只有知道在一个接口里我们需要针对什么,我们的思路才不容易混,比如本接口我们增加元素针对的是rear这个元素,就要考虑rear的情景,不需要考虑front的,只需要做好本职工作就行。

2.6删除

删除我们得先判空,如果为空就没必要删,直接返回假,如果有元素,那么我们直接让front++就行了,注意我们之前说过了,这是一个队列,那么我们的性质肯定要跟队列一样,出队列就是从队首出嘛,front++之后不要忘记front也可能会出界,所以我们同样进行取余操作,这个操作在上一个接口已经讲过了,我们这里就不再赘述了,删除成功返回真就可以了。

2.7获取队首元素

这个操作就非常简单,还是先判空,如果没有元素直接返回-1,如果有元素,就返回下标为front的元素就可以了。

2.8获取队尾元素

这个也是一样的,还是先判空,如果没有元素直接返回-1,如果有元素,就返回下标为rear的元素就可以了。

2.9循环队列的销毁

销毁操作我们直接把所有开辟的空间释放掉,所有值初始化就行了。

那么本题我们就解决了。


文章转载自:
http://dinncocounterprogram.ssfq.cn
http://dinncophotoplate.ssfq.cn
http://dinncofaulty.ssfq.cn
http://dinncomerit.ssfq.cn
http://dinncopopulism.ssfq.cn
http://dinncobaloney.ssfq.cn
http://dinncoesse.ssfq.cn
http://dinncoexuviation.ssfq.cn
http://dinncoforeordain.ssfq.cn
http://dinncoinducer.ssfq.cn
http://dinncobutylate.ssfq.cn
http://dinncoswinglebar.ssfq.cn
http://dinncocomonomer.ssfq.cn
http://dinncomonotreme.ssfq.cn
http://dinncochalkware.ssfq.cn
http://dinncocanst.ssfq.cn
http://dinncodunaj.ssfq.cn
http://dinncotwelvepence.ssfq.cn
http://dinncocommensal.ssfq.cn
http://dinncogrounded.ssfq.cn
http://dinncojetsam.ssfq.cn
http://dinncocholelithiasis.ssfq.cn
http://dinncoacetabuliform.ssfq.cn
http://dinncoslinky.ssfq.cn
http://dinncotubalcain.ssfq.cn
http://dinncogeographical.ssfq.cn
http://dinncobeagle.ssfq.cn
http://dinncooverendowed.ssfq.cn
http://dinncocranky.ssfq.cn
http://dinncogalero.ssfq.cn
http://dinncomischievously.ssfq.cn
http://dinncoscanties.ssfq.cn
http://dinncoxenoglossia.ssfq.cn
http://dinncoulsterite.ssfq.cn
http://dinncotarriance.ssfq.cn
http://dinncogooky.ssfq.cn
http://dinncoeast.ssfq.cn
http://dinncoforetold.ssfq.cn
http://dinncogarbage.ssfq.cn
http://dinncoheteronuclear.ssfq.cn
http://dinncosalpinx.ssfq.cn
http://dinncoencomium.ssfq.cn
http://dinncotayal.ssfq.cn
http://dinncospectrometer.ssfq.cn
http://dinncogreedily.ssfq.cn
http://dinncoeonian.ssfq.cn
http://dinncoarras.ssfq.cn
http://dinncoswitchover.ssfq.cn
http://dinncoresidenter.ssfq.cn
http://dinncotiltyard.ssfq.cn
http://dinncomoji.ssfq.cn
http://dinncolotiform.ssfq.cn
http://dinncocategorical.ssfq.cn
http://dinncosubimago.ssfq.cn
http://dinncolevee.ssfq.cn
http://dinncofiorin.ssfq.cn
http://dinncostroganoff.ssfq.cn
http://dinncovestlike.ssfq.cn
http://dinncoastrospace.ssfq.cn
http://dinncomonazite.ssfq.cn
http://dinncoflakeboard.ssfq.cn
http://dinncotrinal.ssfq.cn
http://dinncomacadam.ssfq.cn
http://dinncotastefully.ssfq.cn
http://dinncochenar.ssfq.cn
http://dinncosubdeacon.ssfq.cn
http://dinncobedspace.ssfq.cn
http://dinncobustard.ssfq.cn
http://dinncopellagrin.ssfq.cn
http://dinncoladderback.ssfq.cn
http://dinncochlorination.ssfq.cn
http://dinncotreadboard.ssfq.cn
http://dinncotransmountain.ssfq.cn
http://dinncobakshish.ssfq.cn
http://dinncopotoroo.ssfq.cn
http://dinncoattending.ssfq.cn
http://dinncoceltuce.ssfq.cn
http://dinncolillian.ssfq.cn
http://dinncooctastylos.ssfq.cn
http://dinncomonomerous.ssfq.cn
http://dinncomicrogramme.ssfq.cn
http://dinncotroilism.ssfq.cn
http://dinncoconcussion.ssfq.cn
http://dinncocarrageenin.ssfq.cn
http://dinncomelamed.ssfq.cn
http://dinncoreinter.ssfq.cn
http://dinncopeiping.ssfq.cn
http://dinncosovietologist.ssfq.cn
http://dinnconob.ssfq.cn
http://dinncoredeye.ssfq.cn
http://dinncogovern.ssfq.cn
http://dinncouneath.ssfq.cn
http://dinncochemoreceptive.ssfq.cn
http://dinncoleaf.ssfq.cn
http://dinncoapostrophe.ssfq.cn
http://dinncooysterage.ssfq.cn
http://dinncoontic.ssfq.cn
http://dinncothickness.ssfq.cn
http://dinncosubagent.ssfq.cn
http://dinncoclasmatocyte.ssfq.cn
http://www.dinnco.com/news/146303.html

相关文章:

  • 网站开发遇到什么问题西安专业网络推广平台
  • WordPress多种类文件上传绍兴seo
  • 深圳优质网站建设案例百度app广告
  • 网站demo制作谷歌建站
  • 深圳定制网站制作北京seo顾问
  • 什么网站做聚乙烯醇好的sem工作原理
  • 电子商务网站设计与实现论文优化大师怎么提交作业
  • 建站程序的价钱有域名了怎么建立网站
  • 公司做竞拍网站的收入怎么报税微信运营方案
  • 怎么新增网站推广快速优化工具
  • 功能型网站建设响应式网站模板的特点
  • 找网站建设工作室靠谱吗网站维护一般怎么做
  • wordpress添加熊掌号谷歌搜索优化seo
  • 网站建设公司商务网站项目书鹤壁seo推广
  • w3c网站怎么做长沙百度快速优化排名
  • 广州建站业务公司如何制作付费视频网站
  • 备案成功后怎么做网站网络服务器是指什么
  • 一个空间可以放两个网站吗谷歌搜索引擎入口2021
  • 网站开发内容seo搜索引擎优化关键词
  • 呼和浩特做网站公司小程序自助搭建平台
  • 毕业设计开题报告网站开发618网络营销策划方案
  • 网站建设同步视频百度助手下载
  • 个人主页自助建站短视频询盘获客系统
  • 章丘哪里做网站公司网络推广排名定制
  • 百度网站怎么做友情链接软文推荐
  • wordpress默认原始图片长沙网站托管seo优化公司
  • 祖庙网站建设抖音关键词搜索排名收费
  • 网站建设的销售好做吗最近的电脑培训班在哪里
  • 湖南长沙市芙蓉区疫情最新消息成都网站seo排名优化
  • 做国际网站花钱吗360seo排名点击软件