array is of same type and linked list is of different type
In an int开发者_如何学Goerview 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?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.
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
int[] myArray = new int[20];
So they learn that they must determine the type...
and when they build a node
prev= object;
next = object;
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 :)
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.
精彩评论