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

2019-08-22:说一说数组和链表的区别? #127

Open
MoJieBlog opened this issue Aug 22, 2019 · 3 comments
Open

2019-08-22:说一说数组和链表的区别? #127

MoJieBlog opened this issue Aug 22, 2019 · 3 comments

Comments

@MoJieBlog
Copy link
Collaborator

No description provided.

@DaveBoy
Copy link

DaveBoy commented Aug 22, 2019

内存上是否连续,新增删除的效率,查询的效率,底层数据结构的区别

@gabyallen
Copy link

gabyallen commented Aug 22, 2019

数组静态分配内存,链表动态分配内存;

数组在内存中连续,链表不连续;

数组元素在栈区,链表元素在堆区;

数组利用下标定位,时间复杂度为O(1),链表定位元素时间复杂度O(n);

数组插入或删除元素的时间复杂度O(n),链表的时间复杂度O(1).

@MrShuHong
Copy link

数组在内存上市连续且每个内存大小是相同的,如果插入或者删除,为了保证内存的连续,需要移动大量的内存地址,腾出空间。 而链表内存不是连续的,而是通过指针来讲上下两个元素联系起来,因此插入和删除元素都不需要移动内存,只需要改变指针指向。所以数据适合访问,链表适合插入移除。另外数组是在栈中分配内存,而链表是在堆中分配内存。

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

No branches or pull requests

4 participants