Recommended visual data structure and algorithmic tools http://zh.visualgo.net/
Click the first figure to sort it in
Two modes in the upper right corner: Teaching Mode browse mode
Let me do this. Select the sort process
Point to the top of the Select
Click Create in the lower left corner
Random randomly generated points can also be, or you can enter a number yourself. Note that it's only 1-50.
Take care not to point sorted,nearly Sorted.
Then go
You'll find the visualization area
Open the bottom right corner of the two box at the same time
This is the interface we're going to work on.
Now click Create under the sort
Go
The visualization area is moving, move the bottom left corner to the slow, then press the keyboard ← (the left key of the arrow key, not fallback OH)
That is, you can use the arrow keys to control the operation of the animation.
Pseudo code can not see, the focus is the orange part and animation
Select Sort First Step
Set 1 as the current minimum, then iterate through the remaining unsorted elements to find the true minimum.
Set the first number 1 to the current minimum and traverse the unordered element to find the correct minimum value.
Step Two
At this time found a smaller than 3,
3 The values behind this round are compared to 1.
In conclusion, we can understand why it takes three variables to select a sort. Note that the visualization area has three colors in addition to the original light blue color.
Select: The first comparison with the 2,3,4 behind the selection of the smallest. In turn, the traversal, which is the inner traversal (2)
The second one ....
This is an outer traversal (1)
But we can not choose the number of every time is the minimum (unless it has been lined up), if we find that the first number of the round is small, we have to give him the least value of the honor, the people behind him compared to him, if the younger than he was awarded to the other smaller.
So we need a variable to store the minimum value. (3)
VISUALGO data structure and algorithm visualization tools