链表上的数组 [英] Array over linked list

查看:116
本文介绍了链表上的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





链接列表总是比数组更受欢迎。那为什么我们需要数组呢?在这种情况下,我们将使用数组链表?



我尝试过:



只是一个理论问题,没有关于代码

Hi,

Linked list is always preferred over array. Then why we need array? In which case we will use array over linked list?

What I have tried:

Just a theory question, nothing about code

推荐答案

数组更容易编码,可以使用索引进行迭代。链接列表上的操作(如插入或排序)比数组更广泛。



今天的数组实现只对对象进行了排序指针,因此对象不会被操作移动,而是便宜的指针。
An array is easier to code and can be iterated with an index. Operations on linked lists like inserting or sorting are more expansive than arrays.

Array implementations are today only sorted pointers on objects, so objects arent moved by operations, but cheap pointers.


Quote:

链接列表总是比数组更受欢迎。

Linked list is always preferred over array.



谁说的?

这就像说螺丝刀总是比锤子更受欢迎一样愚蠢。

这些是不同用途的不同工具。 br />


链接列表擅长调整大小和排序,随机访问很糟糕。

数组擅长随机访问,不好看调整大小和插入排序。


Who said that ?
This is as stupid as saying that "Screw driver is always preferred over hammer."
Those are different tools for different usages.

Linked list is good at resizing and sorting, it is bad at random access.
Array is good at random access, it is bad at resizing and insertion sort.


Quote:

链接列表总是比数组更受欢迎。

Linked list is always preferred over array.

这是完全错误的。事实上,阵列是最常用的容器。



我建议你学习阵列和链表功能,它们在基本操作(构造,插入,移除,破坏......)上的表现以及最终的表现各种场景(例如搜索,排序)。



最后一点:现代CPU架构(例如内存缓存)有利于阵列性能。

That's plain wrong. As matter of fact the array is the most used container.

I suggest you to study array and linked list features, their performance on basic operations ( construction, insertion, removal, destruction, ...) and finally their performance on various scenarios (e.g. searching, sorting).

A final note: modern CPU architectures (e.g. memory cache) favour array performance.


这篇关于链表上的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆