0
what's the different between array and linked list
3 Respostas
+ 1
An array has a chunk of memory that houses the arrays element slots. They sit in order perfectly spaced apart. The name of the array is the means of referring to the base of the array, i.e. arr[0], and the number in the brackets to index into it is how many bits multiplied by the size of an element to shift along in memory to find the element you want (hence [0] being the base as it's not adding anything).
A linked list on the other hand is as if those array elements were spaced apart arbitrarily in memory, and not necessarily in the order of the list. Linked lists use up more space and take more time to traverse as pointers to the next element in the list are used to store where the next element is; and also to traverse the whole thing to find what you're after.
Have a read into single and doubly linked lists while you're at it.
0
thanks , but Which is better to write the code ?
0
From an industry standard I don't know. Generally an array is faster and linked lists/vectors are safer; broadly speaking. Hopefully someone else can give a definite answer.