-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Fundamentals for Self-Taught Programmers
By :
To recap what you learned in the previous chapter, the selection sort algorithm searches for the smallest value within the array and then moves the smallest value to the front of the array so that the array will be sorted in ascending order. Let’s identify a few things about this algorithm that will help us build it in C#. First, we’ll need to search the entire array until the smallest value is found, so we’ll need some iteration, such as a for loop, to visit every item in the array.
Tip
It’s important to note here that algorithms are meant to be abstract, meaning that this algorithm will be able to work with any numerical array. The array in the example is a test array to make sure we’re on the right track.
Let’s begin by creating a small array and a loop to do this:
int[] testArray = {13, 55, 0, -4, 80, 7, 20};
for (int index = 0; index < testArray.Length; index++)
{
...