Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
As an example of developing a complete program, today we write a “selection sort” algorithm.See Chapter 8.
Sorting is very important. For example, it is used in Google’s indexing of web sites to speed searches
See this web simulation of sorting algorithms https://www.toptal.com/developers/sorting-algorithms
Ready to click “Play All” next
THESE HAVE ALREADY FINISHEDPART WAY THROUGHTHE SORT
I often start with sketching and outlining the problem on a piece of paper.
Here, we start working on the “Selection Sort” algorithm
In the next slides, we use “temp” instead of “a” for the swap variable name
start by outlining with comments, write a line or two, then test
In order to do more scans of the vector, weneed to make this into a variable… this is also aproblem if v(1) is the lowest value since lowValue andlowVindex will be unknown variables in the fprintf’s
convert some more numeric constantsto variables
Now, repeat scanning the vector
now that we are done, we can comment the rng lineand get a new vector each run