You are on page 1of 5

Lesson 5:

C++ Linked Lists


What is Linked List?
• C++ List is a container that stores elements randomly in unrelated locations. To maintain sequential
ordering, every list element includes two links:

• one that points to the previous element


• another that points to the next element
Why Linked List is Important?
• Dynamic Size: Linked lists can grow or shrink in size dynamically. Unlike arrays, where the size
is typically fixed, linked lists can easily accommodate data of varying lengths.

• Efficient Insertions and Deletions: Linked lists excel in insertions and deletions, especially in the
middle of the list
• Constant-Time Insertions/Deletions at the Beginning: For singly linked lists, inserting or
deleting a node at the beginning of the list is a constant-time operation (O(1)). This is not the case
with arrays, where elements need to be shifted.

• Support for Dynamic Data: When you don't know the size of the data in advance, linked lists
can adapt easily. For example, in streaming applications or when dealing with data from external
sources, linked lists can be an excellent choice.

• Real-World Applications: Linked lists are used in many real-world applications. For example, in
web browsers, they can represent the history of visited pages, in word processors for undo/redo
functionality, and in music and video players for playlists.
Components of a Linked Lists
• Node: The fundamental building block of a linked list.

• Data: The actual value or information stored in each node.


• Pointer/Reference: Establishes connections between nodes.
Q&A and Discussion

You might also like