00:01
This question asks us to animate insertion sort.
00:03
We begin with 20 distinct numbers in random order, display them as a histogram, and each time the user clicks step, the program performs one pass of the outer loop.
00:12
The main idea of insertion sort is that we take the next unsorted value and inserted into the correct place and the already sorted part on the left.
00:19
So we need a variable to mark how much of the list is already sorted.
00:23
A variable like self .i can represent the index of the value that we're about to insert.
00:29
We start at 1 because a single element at index 0 is already sorted by itself.
00:37
When the user clicks step, we save the current value, compare it to the items before, shipped larger values of the right, and then place the saved value into its correct spot.
00:58
So j equals self .i minus 1, while j greater than are equal to 0, and self...