Insertion Sort Algorithm
15 9 9 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 1
innerIndex: 1
Insertion Sort Algorithm
15 9 9 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 1
innerIndex: 1
9 smaller than 15,
so they need to swap
Insertion Sort Algorithm
9 15 9 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 1
innerIndex: 1
Insertion Sort Algorithm
9 15 9 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 1
innerIndex: 0
innerIndex no longer bigger than
zero, inner loop exits
Insertion Sort Algorithm
9 15 9 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 2
innerIndex: 2
Insertion Sort Algorithm
9 9 15 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 2
innerIndex: 2
9 and 15 swapped
Insertion Sort Algorithm
9 9 15 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 2
innerIndex: 1
innerIndex moved left
Insertion Sort Algorithm
9 9 15 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 2
innerIndex: 1
9 is not smaller than 9,
inner loops exits
Insertion Sort Algorithm
9 9 15 10 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 3
innerIndex: 3
Insertion Sort Algorithm
9 9 10 15 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 3
innerIndex: 3
10 and 15 swapped
Insertion Sort Algorithm
9 9 10 15 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 3
innerIndex: 2
10 is not smaller than 9,
inner loops exits
Insertion Sort Algorithm
9 9 10 15 12 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 4
innerIndex: 4
Insertion Sort Algorithm
9 9 10 12 15 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 4
innerIndex: 4
12 and 15 swap
Insertion Sort Algorithm
9 9 10 12 15 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 4
innerIndex: 3
12 is not smaller than 10,
inner loops exits
Insertion Sort Algorithm
9 9 10 12 15 1 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 5
innerIndex: 5
Insertion Sort Algorithm
9 9 10 12 1 15 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 5
innerIndex: 5
1 and 15 swap
Insertion Sort Algorithm
9 9 10 12 1 15 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 5
innerIndex: 4
Insertion Sort Algorithm
9 9 10 1 12 15 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 5
innerIndex: 4
1 and 12 swap
Insertion Sort Algorithm
9 9 10 1 12 15 11 3 9
0 1 2 3 4 5 6 7 8
currentStartIndex: 5
innerIndex: 3
…etc…

Insertion Sort Algorithm