Selection sort in binary search

Saratvaddilli
Posted by Saratvaddilli under C# category on | Points: 40 | Views : 1580
            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;
}

Comments or Responses

Login to post response