Reputation: 332
LinkedList by nature does not have capacity since it does not allocate memory to the items before the items are added to the list. Each item in a LinkedList holds a pointer to the next in the list. There is no meaning of initial capacity. Then why does the piece of code is working in Java?
LinkedList<Integer> adjListArray[];
// define the size of array as number of vertices
adjListArray = new LinkedList[V];
Link to the whole program in Java - Graph Representaions
Upvotes: 0
Views: 71
Reputation: 394156
There's no initial capacity in this snippet.
You are declaring an array of LinkedList
s (adjListArray
), and V
is the length of that array (i.e. the array can hold references to V
LinkedList
instances).
Upvotes: 4