Jump to content

4.1.1.2 Linked Lists (Singly, Doubly, Circular)

From Computer Science Knowledge Base

4.1.1.2 Linked Lists: A Chain of Information

Imagine a treasure hunt where each clue tells you where to find the next clue. A linked list is similar! Instead of items being in numbered boxes like an array, each item (called a "node") holds its own piece of information and a pointer (or link) to the next item in the list. They're like a chain where each link knows where the next link is.

This is different from arrays because items in a linked list don't have to be right next to each other in the computer's memory. They can be scattered around, but the links connect them in order.

Singly Linked Lists

A singly linked list is like a one-way street or a simple chain. Each item points only to the next item in the list. You can easily go forward, but you can't go backward without starting from the beginning again. The very last item points to nothing, which tells the computer it's the end of the list.

  • Example: A playlist where you usually just listen to songs in order.

Doubly Linked Lists

A doubly linked list is like a two-way street or a chain where each link knows both the link before it and the link after it. Each item has a pointer to the next item AND a pointer to the previous item. This means you can easily move forward or backward through the list.

  • Example: The "undo" and "redo" buttons in a drawing program, or skipping forward and backward in a music player.

Circular Linked Lists

A circular linked list is like a merry-go-round or a string of fairy lights where the last light connects back to the first one. In this type of list, the very last item points back to the first item, creating a continuous loop. There's no "end" to the list!

  • Example: A repeating song playlist, or a game where characters take turns in a circle.

Bibliography for Linked Lists