Disadvantages of Arrays: Fixed size (static in nature) In efficient memory allocation and utilization Slow insertion or deletion time
How to maintain this list in memory
Definition of linked list: Linked List can be defined as a collection of objects Objects called nodes that are randomly stored in the memory. A node contains two fields data link Data field stores data/information at that particular address and the link or pointer or address field which contains the address of the next node in the memory.
Types of linked lists: Single linked list: Navigation is forward. Double linked list: Forward and backward navigation is possible. Circular linked list: The last element is linked to the first element.
Singly Linked List
Representation of Single Linked List
Let's see how each node of the linked list is represented. Each node consists: A data item An address of another node
How to Create a node of the List?
Head->Link ? Head -> Link -> Link ?
Final Code
Traversing a Single Linked List (Counting the Nodes)
Traversing a Single Linked List (Printing the Data)