6 Linked List
6 Linked List
Data Structures
Lecture : Linked List
Outlines
• Introduction
• Why Linked List?
• Types of Linked List
• Memory Representation of Linked Lists
• Difference between Singly Linked List and Arrays
• Program to implement Singly Link list
• Review Questions
Introduction
• A linked list (One-way list) is a linear collection of data
elements, called nodes, where the linear order is given by
means of pointers.
• Second part contains the address of the next node in the list.
Linked List
• A singly linked list is a
concrete data structure
consisting of a sequence of next
nodes
• Each node stores
– element
– link to the next node node
element
A B C D
Key Points
Linked list
• Linear collection of nodes
• Connected by pointer links
• Accessed via a pointer to the first node of the list
• Link pointer in the last node is set to null to mark the
list’s end
• Linked list contains a List Pointer Variable called
START or NAME, which contains the address of the
first node.
Why Linked List?
Arrays: pluses and minuses
+ Fast element access.
-- Impossible to resize.
INFO LINK
Start 2 1
A 6
2
E 9
3
C 7
4
5
B 4
6 D 3
7
8 F 0
9
10
Memory Representation (2)
• Multiple lists in memory
INFO LINK
Start1 1 S4 0
2
2 A 6
3 E 9
Start 210 4 C 7
5 S2 8
6 B 4
7 D 3
8 S3 1
F 0
9
S1 5
10
Memory Representation (3)
• INFO part of a node may be a record with multiple data items.
• Records in memory using Linked lists