0

what's the different between array and linked list

19th Aug 2016, 6:50 PM
Amel Alrooh
Amel Alrooh - avatar
3 Answers
+ 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.
20th Aug 2016, 3:35 AM
Ahkrin
0
thanks , but Which is better to write the code ?
21st Aug 2016, 6:26 AM
Amel Alrooh
Amel Alrooh - avatar
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.
23rd Aug 2016, 9:08 PM
Ahkrin