Professional Documents
Culture Documents
1. find(52) // return 2
2. insert(70, 2) // 34 12 70 52 16 12
3. remove(2) // 34 12 70 16 12
List Implementations
Using arrays
Using linked list
Array Implementation of Lists
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5 33 11 13 40
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5 33 11 13 40
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5
insert(70, 2)
0 1 2 3 4 5 6 7 8 9
A 52 48 70 16 25 31 5
Array Implementation of Lists
insert(item, index) - O(n)
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5 33 11 13 40
insert(70, 2)
Array Implementation of Lists
insert(item, index) - O(n)
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5 33 11 13 40
insert(70, 2)
Display error message then terminate
Create bigger array and copy contents of smaller
array to new array
Array Implementation of Lists
insert(item, index) -
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5
remove(0)
0 1 2 3 4 5 6 7 8 9
A 48 16 25 31 5
Array Implementation of Lists
remove(index) - O(n)
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5
remove(7)
Array Implementation of Lists
remove(index) - O(n)
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5
remove(7)
Display error message then terminate
Array Implementation of Lists
remove(index)
0 1 2 3 4 5 6 7 8 9
A 52 48 16 25 31 5
Consists of nodes
Linked list Implementation of List
Nodes
beginMarker
endMarker
Linked list Implementation of List
A linked list
findKth - linear
findKth(4)
start at first node and traverse the list following until the
fourth element
Linked list Implementation of List
Insertion into a linked list
Linked list Implementation of List
Deletion from a linked list
Linked list Implementation of List
To avoid the linear time operations for adding and
removing elements, we will think of lists as formed
by putting together Nodes that can be connected
next
previous
Linked list Implementation of List
To avoid the linear time operations for adding and
removing elements, we will think of lists as formed
by putting together Nodes that can be connected
Linked list Implementation of List
Doubly linked list with header and tail nodes
Linked list Implementation of List
Doubly linked list with header and tail nodes
Linked list Implementation of List
Insertion in a doubly linked list by getting new node
and then changing the pointers in the order
indicated
Linked list Implementation of List
Removing node specified by p from a doubly linked
list
Summary