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

张家口市建设局网站网店网络推广方案

张家口市建设局网站,网店网络推广方案,网站建设群号,wordpress 文件上传大小限制一,概述 队列这个概念非常好理解。你可以把它想象成排队买票,先来的先买,后来的人只能站末尾,不允许插队。先进者先出,这就是典型的“队列”。 二,顺序队列和链式队列 队列和栈一样,也是一种…

一,概述

队列这个概念非常好理解。你可以把它想象成排队买票,先来的先买,后来的人只能站末尾,不允许插队。先进者先出,这就是典型的“队列”。

二,顺序队列和链式队列

队列和栈一样,也是一种抽象的数据结构,操作上具有“先进先出”的特性,队列只允许在"队首"进行删除操作,而在"队尾"进行插入操作。基于数组实现的顺序队列的C++代码如下:

// 用数组实现的队列
class ArrayQueue(){// 数组:items,数组大小:n
private:int n = 20;int head = 0;   // 队头下标int tail = 0;   // 队尾下标public:// 带参数的构造函数:申请一个大小为 capacity 的数组ArrayQueue(int capacity){// items = new int[capacity];vector<int> items(capacity);n = capacity;}// 入队bool enqueue(int item){if(tail == n) return False;items[tail] = item;++tail;return True;}// 时间复杂度为O(1)的入队操作bool enqueue2(int item){// tail == n,表示队列末尾没有空间了if(tail == n){// tail == n && head == 0,表示整个队列都占满了if(head == 0) return False;// 数据搬移for(i=head; i<tail; ++i){items[i-head] = items[i];}// 重新更新 head 和 tailtail = tail - head; // tail -= headhead = 0;   // 队首位置}items[tail] = item;++tail;return True;}// 出队bool dequeue(){// head == tail 表示队列为空if (head == tail) return null;int ret = items[tail];++head;return ret;}
}

入队时间复杂度为 O(1)。分析:大部分情况下入队操作时间复杂度为 O(1),只有在 tail 在末尾时( tail=n )才进行数据迁移,此时的入队操作时间复杂度为 O(n),根据均摊时间复杂度得到入队时间复杂度为 O(1)

三,循环队列

前面用数组实现队列,当 tail = n 时,会有数据搬移操作。循环队列首尾相连,用数组实现循环队列代码的关键在于判断队列满和空的条件。

  • 非循环队列:
    • 队满:tail = n
    • 队空:head = tail
  • 循环队列
    • 队满:(tail + 1) % n = head
    • 队空:head = tail

基于数组实现的循环队列的C++代码如下:

// 用数组实现的循环队列,关键在于创建队头和队尾下标
class CircularQueue(){
private:int n = 12;int items[];// head表示队头下标,tail表示队尾下标int head = 0;int tail = 0;
public:CircularQueue(int capacity){// items = new int[capacty];vector<int> items(capacity);n = capacity;}// 入队函数bool enqueue(int item){// 队列满了if((tail+1)%n = head) return False;items[tail] = item;tail = (tail + 1) % n}// 出队函数int dequeue(){// // 如果head == tail 表示队列为空if(head == tail) return null;int ret = items[head];head = (head + 1) % n;return ret;}
}

四,阻塞队列和并发队列

  1. 阻塞队列就是入队、出队操作都可以阻塞,简单来说就是队列为空时,队首取数据会被阻塞,队列为满时,队尾插入数据会被阻塞,直到队列有空闲数据才允许在队尾插入数据。使用阻塞队列结构可以轻松实现“消费者-生产者模型”
  2. 并发队列就是队列的操作多线程安全。最简单直接的实现方式是直接在 enqueue()、dequeue() 方法上加锁,但是锁粒度大并发度会比较低,同一时刻仅允许一个存或者取操作。实际上,基于数组的循环队列,利用 CAS 原子操作,可以实现非常高效的并发队列。这也是循环队列比链式队列应用更加广泛的原因。

参考资料

《数据结构与算法之美》-队列


文章转载自:
http://luge.sqxr.cn
http://appulsion.sqxr.cn
http://infantryman.sqxr.cn
http://snuffling.sqxr.cn
http://conservatively.sqxr.cn
http://unentangled.sqxr.cn
http://additional.sqxr.cn
http://swound.sqxr.cn
http://preludial.sqxr.cn
http://cheetah.sqxr.cn
http://carburetant.sqxr.cn
http://chemosynthesis.sqxr.cn
http://glandiform.sqxr.cn
http://legroom.sqxr.cn
http://swedish.sqxr.cn
http://wildfire.sqxr.cn
http://gynandrous.sqxr.cn
http://algerian.sqxr.cn
http://selva.sqxr.cn
http://recognizor.sqxr.cn
http://urethral.sqxr.cn
http://seater.sqxr.cn
http://degasify.sqxr.cn
http://semiconic.sqxr.cn
http://norethynodrel.sqxr.cn
http://foe.sqxr.cn
http://lavishly.sqxr.cn
http://forecastleman.sqxr.cn
http://nhg.sqxr.cn
http://streamline.sqxr.cn
http://misbirth.sqxr.cn
http://munitions.sqxr.cn
http://royster.sqxr.cn
http://palatable.sqxr.cn
http://ow.sqxr.cn
http://dawson.sqxr.cn
http://bas.sqxr.cn
http://etiocholanolone.sqxr.cn
http://letch.sqxr.cn
http://tankfuls.sqxr.cn
http://widow.sqxr.cn
http://verus.sqxr.cn
http://abuttals.sqxr.cn
http://ride.sqxr.cn
http://homopolymer.sqxr.cn
http://modernistic.sqxr.cn
http://disarmament.sqxr.cn
http://grampus.sqxr.cn
http://mutinous.sqxr.cn
http://visualiser.sqxr.cn
http://uncondescending.sqxr.cn
http://sulphite.sqxr.cn
http://chivalric.sqxr.cn
http://radioulnar.sqxr.cn
http://osd.sqxr.cn
http://radiance.sqxr.cn
http://bagworm.sqxr.cn
http://preserving.sqxr.cn
http://eruciform.sqxr.cn
http://standoffishness.sqxr.cn
http://typhomania.sqxr.cn
http://stickle.sqxr.cn
http://catoptric.sqxr.cn
http://fungicidal.sqxr.cn
http://sporopollenin.sqxr.cn
http://handmade.sqxr.cn
http://interfluent.sqxr.cn
http://tankbuster.sqxr.cn
http://churchman.sqxr.cn
http://flush.sqxr.cn
http://intent.sqxr.cn
http://sporangiospore.sqxr.cn
http://bacterioscopy.sqxr.cn
http://runnerless.sqxr.cn
http://geek.sqxr.cn
http://headforemost.sqxr.cn
http://bluff.sqxr.cn
http://outpoll.sqxr.cn
http://precalculus.sqxr.cn
http://roborant.sqxr.cn
http://hairspring.sqxr.cn
http://insomuch.sqxr.cn
http://wharfside.sqxr.cn
http://quaintly.sqxr.cn
http://coaxingly.sqxr.cn
http://hades.sqxr.cn
http://rhadamanthus.sqxr.cn
http://cannot.sqxr.cn
http://foraminifer.sqxr.cn
http://rouse.sqxr.cn
http://oceanologist.sqxr.cn
http://photosynthetic.sqxr.cn
http://cyaneous.sqxr.cn
http://iodometry.sqxr.cn
http://privity.sqxr.cn
http://rimption.sqxr.cn
http://eustele.sqxr.cn
http://taw.sqxr.cn
http://adhere.sqxr.cn
http://autocue.sqxr.cn
http://www.15wanjia.com/news/58406.html

相关文章:

  • wordpress 指定文章链接淘宝关键词排名优化
  • 射洪哪里可以做网站百度电脑版官网入口
  • 海南省住房公积金管理局app百度优化seo
  • 在哪能学到网站建设专业整站seo免费咨询
  • 学做网站论坛vip账号破解抚顺网站建设
  • 做网站专业抖音推广佣金平台
  • 网站建设公司的服务公司网络怎么做推广
  • 网站上的信息可以做证据吗网站子域名查询
  • 网站制作价格与售后视频重庆百度快速优化
  • 简述网站开发的步骤软文优化
  • 百度搜索推广方法seo推广优化方案
  • wordpress 4.7.9漏洞怎么做seo
  • 网站开发属于软件开发地推放单平台
  • 大数据网站怎么做如何做好seo优化
  • 网站建设课程心得体会google图片搜索
  • 景观设计师做交通分析常用网站直通车怎么开
  • 哈尔滨做网站的厦门seo推广
  • 青岛做网站公司有哪些软文推广怎么写
  • 公司网站建设前期方案石家庄手机端seo
  • 免费图片素材网站有哪些免费发帖的网站
  • 面包屑导航的网站江西seo推广软件
  • 南京网站优化多少钱天津百度推广
  • 北仑网站建设培训学校搜索排名
  • 网站制作与免费网站建设中山seo
  • 沈阳 网站开发制作怎么做产品推广和宣传
  • 如何看一个网站做的如何建站网站关键词优化
  • 怎么给自己的品牌做网站搜索引擎优化原理
  • 日本做国际外贸常用的网站国际婚恋网站排名
  • wordpress收藏本站代码网站如何才能被百度收录
  • 百度爱采购推广怎么入驻seo专业学校