【发布时间】:2015-07-13 21:41:53
【问题描述】:
在一次采访中,有人问我什么时候数组优于链表? 面试官对我给出的差异不满意,他实际上是在问一些例子。
【问题讨论】:
-
这里是您正在寻找的答案:stackoverflow.com/questions/393556/…
-
我想知道场景而不是链接中提到的差异。
标签: arrays data-structures linked-list
在一次采访中,有人问我什么时候数组优于链表? 面试官对我给出的差异不满意,他实际上是在问一些例子。
【问题讨论】:
标签: arrays data-structures linked-list
数组和链表的一些例子或用法是。
数组。
Arrays are used when the number of items to be stored are known beforehand.
Arrays are used when we want to access the elements through their index (binary search).
Arrays use less memory as compared to linked list.
Sorting in an array is easier.
链表。
Linked list is used when amount of data is not known beforehand.
Linked list takes more memory, as it uses pointer field.
Linked list is comparatively hard to implement.
Sorting a linked list is quite difficult.
【讨论】: