August 2002
Beginner
1122 pages
22h 1m
English
Now that we have stored all of the weights, we want to find the three highest of the weights. We'll use a sorting algorithm called a selection sort, which can be expressed in English as follows:
1. | Repeat the following steps three times, once through for each weight that we want to select. |
2. | Search through the list (i.e., the Weight Vec), keeping track of the highest weight seen so far in the list and the index of that highest weight. |
3. | When we get to the end of the list, store the highest weight we've found in another list (the “output list”, which in this case is the Vec SortedWeight). |
4. | Finally, set the highest weight we've found in the original list to 0, so we won't select it as the highest value again on the next pass ... |
Read now
Unlock full access