Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

数组 #40

Open
jinzhepro opened this issue Apr 21, 2023 · 0 comments
Open

数组 #40

jinzhepro opened this issue Apr 21, 2023 · 0 comments

Comments

@jinzhepro
Copy link
Owner

  • 线性表结构
  • 使用一组连续的内存空间
  • 相同类型数据

线性表结构

数据像一条线一样的结构,只有前,后两个方向.如链表,队列,栈等

连续内存空间

  • 随机访问
  • 插入,删除就要做大量的迁移工作

image

内存地址: a[i]_address = base_address + i * data_type_size

低效的“插入”和“删除”

如果我们在数组最后插入或删除,复杂度为O(1),如果在中间为O(n)

优化

插入:如果数组只是数据集,数据没有规律的情况下,我们可以把插入变成移动.

image-1-1024x458

删除:记录删除数据,将多次删除合并为一次删除.

image-2-1024x279

越界问题

访问到不属于该数组的一块内存地址上,造成bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant