0
Why we store address of next variable in linked list?
Linked list
2 Answers
+ 2
First understand linked list are linked together so answer is just to link :)
Linked list store data in different locations, locations may not be continuous if you don't store location of next variable there is no way to access it later.
For example you want to store 3 values : 11, 23 and 5.
And you choose linked list
suppose computer stored first value 11 with memory location 2500 ,
And second in memory location 3577 and third value in location 5567FF.
In this case you will not be able to access next value until and unless you know memory locations of next variable :)
+ 1
Yes in arrays values are stored in contiguous block of memory so if u have base Address u can access any element in Constant time but in Linkedlist elements are stored at random position so to access another element u need to store Address of next element