Answers for "c# select sort"

C#
0

selection sort in c#

public static void Sort<T>(T[] array) where T : IComparable 
{
    for (int i = 0; i < array.Length - 1; i++) 
    {
        int minIndex = i; 
        T minValue = array[i];
        for (int j = i + 1; j < array.Length; j++) 
        {
            if (array[j].CompareTo(minValue) < 0)
            {
             	 minIndex = j; 
                 minValue = array[j]; 
            } 
        } 
        Swap(array, i, minIndex); 
    }
}
private static void Swap<T>(T[] array, int first, int second)
{
	T temp = array[first]; 
  	array[first] = array[second]; 
  	array[second] = temp;
}
Posted by: Guest on February-24-2022

C# Answers by Framework

Browse Popular Code Answers by Language