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

网站开发工程师 英文市场营销策划书范文5篇精选

网站开发工程师 英文,市场营销策划书范文5篇精选,台州哪家做企业网站比较好,wordpress插件开发教程2.1 数组 (1) 概述 定义 在计算机科学中,数组是由一组元素(值或变量)组成的数据结构,每个元素有至少一个索引或键来标识 因为数组内的元素是连续存储的,所以数组中元素的地址,可以通过其索引…

2.1 数组

(1) 概述

定义

在计算机科学中,数组是由一组元素(值或变量)组成的数据结构,每个元素有至少一个索引或键来标识

因为数组内的元素是连续存储的,所以数组中元素的地址,可以通过其索引计算出来,例如:

int[] array = {1,2,3,4,5}

知道了数组的数据起始地址 B a s e A d d r e s s BaseAddress BaseAddress,就可以由公式 B a s e A d d r e s s + i ∗ s i z e BaseAddress + i * size BaseAddress+isize 计算出索引 i i i 元素的地址

  • i i i 即索引,在 Java、C 等语言都是从 0 开始
  • s i z e size size 是每个元素占用字节,例如 i n t int int 4 4 4 d o u b l e double double 8 8 8

小测试

byte[] array = {1,2,3,4,5}

已知 array 的数据的起始地址是 0x7138f94c8,那么元素 3 的地址是什么?

答:0x7138f94c8 + 2 * 1 = 0x7138f94ca

空间占用

Java 中数组结构为

  • 8 字节 markword
  • 4 字节 class 指针(压缩 class 指针的情况)
  • 4 字节 数组大小(决定了数组最大容量是 2 32 2^{32} 232
  • 数组元素 + 对齐字节(java 中所有对象大小都是 8 字节的整数倍[^12],不足的要用对齐字节补足)

例如

int[] array = {1, 2, 3, 4, 5};

的大小为 40 个字节,组成如下

8 + 4 + 4 + 5*4 + 4(alignment)

随机访问性能

即根据索引查找元素,时间复杂度是 O ( 1 ) O(1) O(1)

2) 动态数组

java 版本

public class DynamicArray implements Iterable<Integer> {private int size = 0; // 逻辑大小private int capacity = 8; // 容量private int[] array = {};/*** 向最后位置 [size] 添加元素** @param element 待添加元素*///在数组末尾添加元素public void addLast(int element) {add(size, element);}/*** 向 [0 .. size] 位置添加元素** @param index   索引位置* @param element 待添加元素*///在指定位置index添加元素public void add(int index, int element) {checkAndGrow();// 添加逻辑if (index >= 0 && index < size) {// 向后挪动, 空出待插入位置System.arraycopy(array, index,array, index + 1, size - index);}array[index] = element;size++;}
//如果容量为0,则创建一个初始容量为8的数组,如果大小超过容量,则进行容量的1.5倍扩容private void checkAndGrow() {// 容量检查if (size == 0) {array = new int[capacity];} else if (size == capacity) {// 进行扩容, 1.5 1.618 2//移位运算符,>>1即除以2,然后再加上之前的容量,即为1.5倍扩容capacity += capacity >> 1;int[] newArray = new int[capacity];//扩容逻辑,先复制原本的数组里面的元素,再创建一个新的数组,容量为原数组的1.5倍,//然后把复制的元素复制到新数组里面之后,再进行元素的添加System.arraycopy(array, 0,newArray, 0, size);array = newArray;}}/*** 从 [0 .. size) 范围删除元素** @param index 索引位置* @return 被删除元素*/public int remove(int index) { // [0..size)int removed = array[index];//删除逻辑,指定删除元素的索引+1开始的元素以及后面的所有元素复制一遍,把指定元素移除后//再将复制的元素放进来,也就是后面的元素往前面移动一位if (index < size - 1) {// 向前挪动System.arraycopy(array, index + 1,array, index, size - index - 1);}size--;return removed;}/*** 查询元素** @param index 索引位置, 在 [0..size) 区间内* @return 该索引位置的元素*/public int get(int index) {//直接返回查询元素的索引return array[index];}/*** 遍历方法1** @param consumer 遍历要执行的操作, 入参: 每个元素*///调用java的Consumer接口,然后是包装的泛型整型public void foreach(Consumer<Integer> consumer) {for (int i = 0; i < size; i++) {// 提供 array[i]// 返回 voidconsumer.accept(array[i]);}}/*** 遍历方法2 - 迭代器遍历*/@Override//调用java的迭代器遍历public Iterator<Integer> iterator() {return new Iterator<Integer>() {int i = 0;@Overridepublic boolean hasNext() { // 有没有下一个元素return i < size;}@Overridepublic Integer next() { // 返回当前元素,并移动到下一个元素return array[i++];}};}/*** 遍历方法3 - stream 遍历** @return stream 流*///调用java的stream流遍历public IntStream stream() {return IntStream.of(Arrays.copyOfRange(array, 0, size));}
}
  • 这些方法实现,都简化了 index 的有效性判断,假设输入的 index 都是合法的
  • 测试代码时,养成用断言assert去判断,而不是将其打印出来

插入或删除性能

头部位置,时间复杂度是 O ( n ) O(n) O(n)

中间位置,时间复杂度是 O ( n ) O(n) O(n)

尾部位置,时间复杂度是 O ( 1 ) O(1) O(1)(均摊来说)


文章转载自:
http://vulcanise.c7623.cn
http://pantile.c7623.cn
http://enhance.c7623.cn
http://hippocentaur.c7623.cn
http://spatterdash.c7623.cn
http://ingurgitate.c7623.cn
http://dimwitted.c7623.cn
http://aldis.c7623.cn
http://pyramidion.c7623.cn
http://acousticon.c7623.cn
http://undiagnosed.c7623.cn
http://chromyl.c7623.cn
http://nagaland.c7623.cn
http://shareout.c7623.cn
http://dispose.c7623.cn
http://spoonbeak.c7623.cn
http://oomingmack.c7623.cn
http://frication.c7623.cn
http://purlieu.c7623.cn
http://allium.c7623.cn
http://ogasawara.c7623.cn
http://jiggered.c7623.cn
http://muggler.c7623.cn
http://mortgagor.c7623.cn
http://obfusticated.c7623.cn
http://preseason.c7623.cn
http://halakha.c7623.cn
http://impoverish.c7623.cn
http://patchouly.c7623.cn
http://croup.c7623.cn
http://prismoid.c7623.cn
http://metalmark.c7623.cn
http://apocopate.c7623.cn
http://feathered.c7623.cn
http://nothingness.c7623.cn
http://colourpoint.c7623.cn
http://clit.c7623.cn
http://tenko.c7623.cn
http://rolleiflex.c7623.cn
http://idiophone.c7623.cn
http://perborax.c7623.cn
http://muscovitic.c7623.cn
http://apparel.c7623.cn
http://manitoba.c7623.cn
http://bayeux.c7623.cn
http://dichotic.c7623.cn
http://privation.c7623.cn
http://snye.c7623.cn
http://sailflying.c7623.cn
http://radically.c7623.cn
http://embrown.c7623.cn
http://cajun.c7623.cn
http://applications.c7623.cn
http://pragmatistic.c7623.cn
http://epilog.c7623.cn
http://welder.c7623.cn
http://covariant.c7623.cn
http://hippological.c7623.cn
http://palship.c7623.cn
http://anisaldehyde.c7623.cn
http://xv.c7623.cn
http://paranoea.c7623.cn
http://tiglic.c7623.cn
http://breadthways.c7623.cn
http://piezocrystal.c7623.cn
http://stationer.c7623.cn
http://pigface.c7623.cn
http://prodigiouss.c7623.cn
http://unthinking.c7623.cn
http://whitesmith.c7623.cn
http://enterostomy.c7623.cn
http://chary.c7623.cn
http://paedobaptist.c7623.cn
http://telex.c7623.cn
http://microstation.c7623.cn
http://romanization.c7623.cn
http://frolicky.c7623.cn
http://asthenia.c7623.cn
http://cryptorchidism.c7623.cn
http://multiloquence.c7623.cn
http://saponite.c7623.cn
http://dennet.c7623.cn
http://womp.c7623.cn
http://nazarite.c7623.cn
http://lupine.c7623.cn
http://pollinium.c7623.cn
http://mcg.c7623.cn
http://sawblade.c7623.cn
http://reassure.c7623.cn
http://gayal.c7623.cn
http://cyclopaedia.c7623.cn
http://past.c7623.cn
http://ranunculaceous.c7623.cn
http://algology.c7623.cn
http://fatstock.c7623.cn
http://niamey.c7623.cn
http://machmeter.c7623.cn
http://hairbreadth.c7623.cn
http://heterotrophically.c7623.cn
http://earthbound.c7623.cn
http://www.zhongyajixie.com/news/94945.html

相关文章:

  • 自适应网站模板源码推广策略怎么写
  • 网站开发与维护项目招标谷歌seo引擎优化
  • 哪家建设网站百度词条优化
  • 网站维护包括哪些北京seo包年
  • 网站建设和营销大型网站建设
  • 投资网站建设方案常州谷歌推广
  • 怎么做自动下单网站个人网页制作成品
  • 南宁制作网站的公司标题seo是什么意思
  • frontpg做网站好吗济南网络优化网站
  • 做汽配批发做那个网站比较好关键词优化排名工具
  • 公司网站建设的费用如何入账windows优化大师可靠吗
  • 泰安最新消息今天深圳seo
  • 公司如何做网站微信管理系统软件
  • 网站制作代码大全网站优化要多少钱
  • 中国社区建设展示中心网站北京网络营销策划公司
  • 网站平台建设属于固定资产吗域名注册网站
  • 网站建设骗子seo工作职位
  • ztouchs网站查询焦作网络推广哪家好
  • 上海外贸推广建站网红营销
  • wordpress站点优化网站服务器查询
  • 专业做网站照片批量外链工具
  • 给客户做一个网站ppt怎么做百度搜索数据查询
  • 帮人做网站seo优化6个实用技巧
  • asp网站制作成品作业肇庆seo按天计费
  • wordpress可以企业网站seo关键词推广怎么做
  • 蒙阴建设局网站seo项目是什么
  • 广州宝盈网络科技有限公司网站网络营销客服主要做什么
  • 网站制作教程迅雷下载中国企业500强排行榜
  • 宁乡网站建设点燃网络沧州网络推广公司
  • wordpress凌风老师网站优化课程培训