what is difference between Array and list?
what is difference between Array and list
Collapse
X
-
Tags: None
-
The main difference between an array and a list is how they internally store the data. In an array the data is stored sequentially in memory.
So if you have an array of integers.
int array[10];
In memory each element (array[0] to array[9]) is stored one after another.
For a list this isn't true. A list contains a pointer to the next element and potentially the previous element for a doubly linked list. The first element in a list is usually refered to as the head and the last element is refered as the tail. -
Yes and the beauty of a list is that you can insert an element anywhere within it whereas in an array you have to move a flock of elements to make room for the new one. A list does not have to be stored in memory sequentially (as in an array) because each node has the address of the next one.Comment
Comment