C#C
C#4y ago
Grin

✅ I'm having trouble understanding what is going on within this selection search

       // The SelectionSort method accepts a string array as an argument.
        // It uses the Selection Sort algorithm to sort the array.
        private void SelectionSort(string[] sArray)
        {

            int minIndex;      // Subscript of minimum value in scanned area
            string minValue;   // Minimum value in the scanned area

            // The outer loop steps through all the array elements,
            // except the last one. The startScan variable marks the
            // position where the scan should begin.
            for (int startScan = 0; startScan < sArray.Length - 1; startScan++)
            {
                // Assume the first element in the scannable area
                // is the minimum value.
                minIndex = startScan;
                minValue = sArray[startScan];

                // Scan the array, starting at the 2nd element in the
                // scannable area, looking for the minimum value.
                for (int index = startScan + 1; index < sArray.Length; index++)
                {
                    if (string.Compare(sArray[index], minValue, true) < 0)
                    {
                        minValue = sArray[index];
                        minIndex = index;
                    }
                }

                // Swap the element with the lesser value with the
                // first element in the scannable area.
                Swap(ref sArray[minIndex], ref sArray[startScan]);
            }
        }

I'm mostly confused about the if statement. What is happening there?
Was this page helpful?