Chapter 3 - Linked Lists
Chapter 3 - Linked Lists
Linked Lists
Our First Data Structure
◦ Linked Lists
Singly
Doubly
Circular
This week we will look at linked lists.
◦ Why to use linked lists?
◦ How to use linked lists?
◦ Different Types of linked list.
But first, lets review arrays.
◦ A very useful structure provided by programming
languages
◦ However, arrays have at least 2 limitations;
The size has to be known at compilation.
The data in the array are separated in the computers
memory by the same distance.
◦ These limitations make ‘inserting’ an item inside
the array difficult.
Linked Lists can be used to get around the
limitations of arrays by linking data
independently from where it is stored in the
computers memory.
To create a linked list, each piece of data in
0
A linked structure is a collection of nodes
storing data and links to other nodes.
Nodes can be located anywhere in memory,
Ex1:
picture a classroom of students who are
seated in no particular order. A unique
number identifies each seat (see next
figure). We’ve also included the relative
height of each student, which we’ll use in
the next exercise.
Let’s say that a teacher needs to place students
names in alphabetical order so she can easily find a
name on the list.
Solutions:
Change their seats (chaotic if many)
leave students seated and make a list of seat
A linked list structure in which each node has pointer to both its successor
and its predecessor.