C# 选择法排序演示

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

public int[] SelectionSort(int[] arr)
{
    //1. Find min
    //2. Swap it with first element
    //3. Repeat starting from secong position onwards.
    int _min = 0;
    for (int i = 0; i < arr.Length; i++)
    {
        _min = i;
        for (int j = i; j < arr.Length; j++)
        {
            if (arr[j] < arr[_min])
                _min = j;
        }
        int _temp = arr[i];
        arr[i] = arr[_min];
        arr[_min] = _temp;
    }
    return arr;
}