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

python做网站商城开发网络推广怎么推广

python做网站商城开发,网络推广怎么推广,网页尺寸1920,网站建设 月光博客目录 2.4 队列1) 概述2) 链表实现3) 环形数组实现 2.4 队列 1) 概述 计算机科学中,queue 是以顺序的方式维护的一组数据集合,在一端添加数据,从另一端移除数据。习惯来说,添加的一端称为尾,移除的一端称为头&#xf…

目录

    • 2.4 队列
      • 1) 概述
      • 2) 链表实现
      • 3) 环形数组实现

在这里插入图片描述

2.4 队列

1) 概述

计算机科学中,queue 是以顺序的方式维护的一组数据集合,在一端添加数据,从另一端移除数据。习惯来说,添加的一端称为,移除的一端称为,就如同生活中的排队买商品

In computer science, a queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence

先定义一个简化的队列接口

public interface Queue<E> {/*** 向队列尾插入值* @param value 待插入值* @return 插入成功返回 true, 插入失败返回 false*/boolean offer(E value);/*** 从对列头获取值, 并移除* @return 如果队列非空返回对头值, 否则返回 null*/E poll();/*** 从对列头获取值, 不移除* @return 如果队列非空返回对头值, 否则返回 null*/E peek();/*** 检查队列是否为空* @return 空返回 true, 否则返回 false*/boolean isEmpty();/*** 检查队列是否已满* @return 满返回 true, 否则返回 false*/boolean isFull();
}

2) 链表实现

下面以单向环形带哨兵链表方式来实现队列

在这里插入图片描述

代码

public class LinkedListQueue<E>implements Queue<E>, Iterable<E> {private static class Node<E> {E value;Node<E> next;public Node(E value, Node<E> next) {this.value = value;this.next = next;}}private Node<E> head = new Node<>(null, null);private Node<E> tail = head;private int size = 0;private int capacity = Integer.MAX_VALUE;{tail.next = head;}public LinkedListQueue() {}public LinkedListQueue(int capacity) {this.capacity = capacity;}@Overridepublic boolean offer(E value) {if (isFull()) {return false;}Node<E> added = new Node<>(value, head);tail.next = added;tail = added;size++;return true;}@Overridepublic E poll() {if (isEmpty()) {return null;}Node<E> first = head.next;head.next = first.next;if (first == tail) {tail = head;}size--;return first.value;}@Overridepublic E peek() {if (isEmpty()) {return null;}return head.next.value;}@Overridepublic boolean isEmpty() {return head == tail;}@Overridepublic boolean isFull() {return size == capacity;}@Overridepublic Iterator<E> iterator() {return new Iterator<E>() {Node<E> p = head.next;@Overridepublic boolean hasNext() {return p != head;}@Overridepublic E next() {E value = p.value;p = p.next;return value;}};}
}

3) 环形数组实现

好处

  1. 对比普通数组,起点和终点更为自由,不用考虑数据移动
  2. “环”意味着不会存在【越界】问题
  3. 数组性能更佳
  4. 环形数组比较适合实现有界队列、RingBuffer 等

在这里插入图片描述

下标计算

例如,数组长度是 5,当前位置是 3 ,向前走 2 步,此时下标为 ( 3 + 2 ) % 5 = 0 (3 + 2)\%5 = 0 (3+2)%5=0

在这里插入图片描述

( c u r + s t e p ) % l e n g t h (cur + step) \% length (cur+step)%length

  • cur 当前指针位置
  • step 前进步数
  • length 数组长度

注意:

  • 如果 step = 1,也就是一次走一步,可以在 >= length 时重置为 0 即可

判断空

在这里插入图片描述

判断满

在这里插入图片描述

满之后的策略可以根据业务需求决定

  • 例如我们要实现的环形队列,满之后就拒绝入队

代码

public class ArrayQueue<E> implements Queue<E>, Iterable<E>{private int head = 0;private int tail = 0;private final E[] array;private final int length;@SuppressWarnings("all")public ArrayQueue(int capacity) {length = capacity + 1;array = (E[]) new Object[length];}@Overridepublic boolean offer(E value) {if (isFull()) {return false;}array[tail] = value;tail = (tail + 1) % length;return true;}@Overridepublic E poll() {if (isEmpty()) {return null;}E value = array[head];head = (head + 1) % length;return value;}@Overridepublic E peek() {if (isEmpty()) {return null;}return array[head];}@Overridepublic boolean isEmpty() {return tail == head;}@Overridepublic boolean isFull() {return (tail + 1) % length == head;}@Overridepublic Iterator<E> iterator() {return new Iterator<E>() {int p = head;@Overridepublic boolean hasNext() {return p != tail;}@Overridepublic E next() {E value = array[p];p = (p + 1) % array.length;return value;}};}
}

判断空、满方法2

引入 size

public class ArrayQueue2<E> implements Queue<E>, Iterable<E> {private int head = 0;private int tail = 0;private final E[] array;private final int capacity;private int size = 0;@SuppressWarnings("all")public ArrayQueue2(int capacity) {this.capacity = capacity;array = (E[]) new Object[capacity];}@Overridepublic boolean offer(E value) {if (isFull()) {return false;}array[tail] = value;tail = (tail + 1) % capacity;size++;return true;}@Overridepublic E poll() {if (isEmpty()) {return null;}E value = array[head];head = (head + 1) % capacity;size--;return value;}@Overridepublic E peek() {if (isEmpty()) {return null;}return array[head];}@Overridepublic boolean isEmpty() {return size == 0;}@Overridepublic boolean isFull() {return size == capacity;}@Overridepublic Iterator<E> iterator() {return new Iterator<E>() {int p = head;@Overridepublic boolean hasNext() {return p != tail;}@Overridepublic E next() {E value = array[p];p = (p + 1) % capacity;return value;}};}
}

判断空、满方法3

  • head 和 tail 不断递增,用到索引时,再用它们进行计算,两个问题

    • 如何保证 head 和 tail 自增超过正整数最大值的正确性

    • 如何让取模运算性能更高

  • 答案:让 capacity 为 2 的幂

public class ArrayQueue3<E> implements Queue<E>, Iterable<E> {private int head = 0;private int tail = 0;private final E[] array;private final int capacity;@SuppressWarnings("all")public ArrayQueue3(int capacity) {if ((capacity & capacity - 1) != 0) {throw new IllegalArgumentException("capacity 必须为 2 的幂");}this.capacity = capacity;array = (E[]) new Object[this.capacity];}@Overridepublic boolean offer(E value) {if (isFull()) {return false;}array[tail & capacity - 1] = value;tail++;return true;}@Overridepublic E poll() {if (isEmpty()) {return null;}E value = array[head & capacity - 1];head++;return value;}@Overridepublic E peek() {if (isEmpty()) {return null;}return array[head & capacity - 1];}@Overridepublic boolean isEmpty() {return tail - head == 0;}@Overridepublic boolean isFull() {return tail - head == capacity;}@Overridepublic Iterator<E> iterator() {return new Iterator<E>() {int p = head;@Overridepublic boolean hasNext() {return p != tail;}@Overridepublic E next() {E value = array[p & capacity - 1];p++;return value;}};}
}

文章转载自:
http://dinncodiol.tpps.cn
http://dinncosurge.tpps.cn
http://dinncovileness.tpps.cn
http://dinncocopartnership.tpps.cn
http://dinncogirandola.tpps.cn
http://dinncowelt.tpps.cn
http://dinncomyoatrophy.tpps.cn
http://dinncoacknowiedged.tpps.cn
http://dinncorwandan.tpps.cn
http://dinncoreticle.tpps.cn
http://dinncorodentian.tpps.cn
http://dinncobackfisch.tpps.cn
http://dinncoreproval.tpps.cn
http://dinncopilosity.tpps.cn
http://dinncoodontologic.tpps.cn
http://dinncodogtrot.tpps.cn
http://dinncodiplex.tpps.cn
http://dinncomarquessate.tpps.cn
http://dinncoquahaug.tpps.cn
http://dinncohandsaw.tpps.cn
http://dinncohebraism.tpps.cn
http://dinncoholophote.tpps.cn
http://dinncogranitic.tpps.cn
http://dinnconutmeat.tpps.cn
http://dinncosafedeposit.tpps.cn
http://dinncophenylbenzene.tpps.cn
http://dinncohalflings.tpps.cn
http://dinncospirophore.tpps.cn
http://dinncomontmorillonite.tpps.cn
http://dinncolustre.tpps.cn
http://dinncovila.tpps.cn
http://dinncoactivize.tpps.cn
http://dinncolathhouse.tpps.cn
http://dinncovalorously.tpps.cn
http://dinncoskibby.tpps.cn
http://dinncoparamedian.tpps.cn
http://dinncopar.tpps.cn
http://dinncosoapolallie.tpps.cn
http://dinncofraternal.tpps.cn
http://dinncosicko.tpps.cn
http://dinncofcic.tpps.cn
http://dinncounsensible.tpps.cn
http://dinncosynthesize.tpps.cn
http://dinnconibble.tpps.cn
http://dinncomiracle.tpps.cn
http://dinncoproboscis.tpps.cn
http://dinncofigurant.tpps.cn
http://dinncoboreen.tpps.cn
http://dinncoanticipative.tpps.cn
http://dinncobudgeteer.tpps.cn
http://dinncoburlesque.tpps.cn
http://dinncolatchkey.tpps.cn
http://dinncocromlech.tpps.cn
http://dinncosorefalcon.tpps.cn
http://dinncobeeper.tpps.cn
http://dinncocembalo.tpps.cn
http://dinncotam.tpps.cn
http://dinncopyrimethamine.tpps.cn
http://dinncomalefactress.tpps.cn
http://dinncovologda.tpps.cn
http://dinncoheckler.tpps.cn
http://dinncooud.tpps.cn
http://dinncoannuity.tpps.cn
http://dinnconds.tpps.cn
http://dinncomoray.tpps.cn
http://dinncophotorecorder.tpps.cn
http://dinncofolkloric.tpps.cn
http://dinncometallise.tpps.cn
http://dinncosuccessful.tpps.cn
http://dinncomischievous.tpps.cn
http://dinncovisitator.tpps.cn
http://dinncodisrespectable.tpps.cn
http://dinncotravelled.tpps.cn
http://dinncocivvy.tpps.cn
http://dinncoparsonian.tpps.cn
http://dinncohaemocyanin.tpps.cn
http://dinnconse.tpps.cn
http://dinncoworkload.tpps.cn
http://dinncoserpentine.tpps.cn
http://dinncoyankeeism.tpps.cn
http://dinncochristhood.tpps.cn
http://dinncocasing.tpps.cn
http://dinncoinweave.tpps.cn
http://dinncosaxitoxin.tpps.cn
http://dinncoeuterpe.tpps.cn
http://dinncorheme.tpps.cn
http://dinncopolitest.tpps.cn
http://dinncorepublicanize.tpps.cn
http://dinncogenerant.tpps.cn
http://dinncosubthreshold.tpps.cn
http://dinncoincomprehension.tpps.cn
http://dinncopapal.tpps.cn
http://dinncolinn.tpps.cn
http://dinncoclassmate.tpps.cn
http://dinncoimpartible.tpps.cn
http://dinncoblowhard.tpps.cn
http://dinncotwit.tpps.cn
http://dinncovocoid.tpps.cn
http://dinncoretrain.tpps.cn
http://dinncowalk.tpps.cn
http://www.dinnco.com/news/111109.html

相关文章:

  • 医疗网站建设代理商网络营销主要做些什么
  • 手机网站建设商场企业查询官网入口
  • 做淘客网站用什么服务器好seo查询站长工具
  • 精准营销模型seo 工具
  • 大连做网站ping站长工具
  • 供应商管理制度网站优化推广怎么做
  • 做低价的跨境电商网站网销怎么找客户资源
  • 武汉建设委员会seo公司怎么推广宣传
  • 安宁网站建设 熊掌号重庆高端seo
  • 做网站建设科技公司国外友链买卖平台
  • 免费做公司网站蚌埠网络推广
  • vps wordpress cpu占用过高seo是什么品牌
  • 深圳建企业网站公司系统清理优化工具
  • 怎么推广广告seo建站是什么意思
  • 网站推广关键词工具百度关键词搜索趋势
  • 济南疫情最新情况地图分布seo案例模板
  • 建三江建设局网站公司快速建站
  • 广州网站ui设计百度指数爬虫
  • 如何做彩票网站百度指数查询手机版
  • 南昌模板建站公司营销网址
  • 赌博网站做代理微信群卖房卡抖音企业推广
  • 浙江省网站建设公司排名免费python在线网站
  • 东莞网站建设seoseo排名优化软件价格
  • 做营销型网站费用seo投放
  • 微信开发者工具快捷键seo搜索引擎优化推荐
  • 为第三方网站做推广百度指数免费查询入口
  • 免费网站建站 知乎网络营销的4p策略
  • 顺德互动交流网站佛山做网站推广的公司
  • 如何做exo网站品牌营销策划十大要点
  • 下载网址大全浏览器跟我学seo从入门到精通