Linked Lists
A Linked List is a collection of
nodes (implemented as a class – as described in Reference program #1) where
each node is connected to the next node by a reference (address).
Each node is implemented as a class
containing two private variables –
·
Data value (could be a
String/integer/double/another class)
·
Reference value of the next node
Unlike an array, where each cell
had a specific cell number and could be accessed independent of other cells,
access to a node (say, X) in a linked list is dependent on having a reference
to the previous node (say, Y).
Example:
Linked Lists
1 - Insert At Back
2 - Quit
what
Integers
Only - Enter Again
The List is
Empty
1 - Insert At Back
2 - Quit
34
Invalid Entry
- Choose From Menu
The List is
Empty
1 - Insert At Back
2 - Quit
1
Enter the
value?
90
The values
so far in the list :
90
1 - Insert At Back
2 - Quit
1
Enter the
value?
789
The values
so far in the list :
90 -->
789
1 - Insert At Back
2 - Quit
1
Enter the
value?
678
The values
so far in the list:
90 -->
789 --> 678
1 - Insert At Back
2 - Quit
2
End of
Program
The values
so far in the list :
90 -->
789 --> 678