在一次采访中,我被问到什么时候数组优先于链接列表? 面试官对我给出的差异不满意,他实际上是在问一些例子。
答案 0 :(得分:0)
数组和链表的一些示例或用法是。
阵列。
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.