数组是同一类型,链表是不同类型
在一次采访中,当我问最近的研究生数组和链表有什么区别时,第一个答案通常是“在数组中你有相同的数据类型,在链表中你可以有不同的数据类型。”当我告诉他们解释时,他们会说他们刚刚在某处读过,或者他们不知道到底是怎么读的。
我真的无法理解这个想法是从哪里进入他们的大脑的?有人可以帮助我理解为什么大学毕业生会这么想吗?或者你认为这真的有区别吗?
In an interview when I ask the recent graduate students that what is the difference between array and linked list, the first answer normally is "In array you have same data types and in the linked list you can have different data types." When I told them to explain they will say that they have just read it somewhere or that they don't know exactly how.
I am really failing to understand from where this idea is coming into their brain? Can someone help me to understand why a college graduate thinks this? Or do you think this is really a difference?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这些学生可能已经学习过静态类型语言的数组和动态类型语言的链表,因此他们已经开始用他们所使用的语言的范例来识别数据结构。
例如,他们可能使用过C 中的数组和Scheme 中的链表。或者无论当今语言的流行名称是什么,本质上都类似于 C,分别是Scheme。
It is possible that these students have been taught arrays with statically typed languages and linked lists with dynamically typed languages, so they have come to identify the data structure with the paradigm of the language they were using it in.
For instance, they may have used arrays in C and linked lists in Scheme. Or whatever the fashionable names are for today's languages that are essentially like C, respectively Scheme.
好吧,我不能代表他们说话,但是当你学习编程时,你会得到一些作业。在一种情况下,您需要将数据保存在数组中,而在另一种情况下,您需要构建一个链接列表来保存数据。当您这样做时,您会发现两者都可以帮助您...将数据保存在内存中...每种都有优点和缺点。
所以感觉是一样的,但他们有限的经验是:
当他们学习声明一个数组时,就像这样
,所以他们知道他们必须确定类型......
并且当他们构建一个节点时,
他们知道他们没有绑定到特定类型或对象。
这是我最好的猜测。
希望有帮助。
PS:看到你给出的答案会很有趣......谁知道呢,他们中的一些人可能会看到它并学到一些东西:)
Well I can't speak for them but when you learn to program you get some assignments. On one you are asked to save data in an array and on another you are asked to build a linked list to save the data. When you do that you learn that both help you... save data in the memory... each with advantages and disadvantages.
So it feels the same but their limited experience is:
when they learn to declare an array it's something like
So they learn that they must determine the type...
and when they build a node
they learn that they are not bound to a specific type or object.
This is my best guess.
Hope it helps.
P.S: It would be interesting to see the answer as you would give it... who knows, some of them may see it and learn something :)
可能会读过 perl,其中列表可以有任何数据类型...但是 perl 和列表有些相似。
另外,c 具有 void * 的概念,因此我们可以将任何数据类型指针类型转换为 void 指针。
May be would have read perl, where lists can have any data types...but there perl and list are somewhat similar.
Also c has concept of void *, so that we can do to have any datatype pointer typecasted to void pointer.
是不是在链表中搜索很容易,而在数组中搜索很复杂,执行其他各种功能(即删除和插入)也是如此。(在删除中,您需要删除您所做的孔,而在插入中,您必须打孔并插入)然后移动所有元素)。
此外,我想你问的问题的解释很简单,因为数组可以保存一种数据类型,例如名称或卷号,而链接列表可以将它们保存在一起。
Isnt it that searching in the linked list is easy while in array is complicated,same goes for various other functions performed i.e deletion and insertion.(In deletion you need to remove the hole that you made and an insertion you have to make a hole and then move ALL the elements).
Moreover,i guess the explanation to the question you asked was easy as an array can hold one data type for example names or roll numbers while Linked list can hold both of them together.