Selection Sort
unknown
java
9 months ago
499 B
6
Indexable
class Solution {
public int selectionSort(int[] nums) {
int i, j, n = nums.length;
int mini, temp;
for(i=0;i<n-1;++i)
{
mini = i;
for(j=i+1;j<n;++j)
{
if(nums[j]<nums[mini])
{
mini = j;
}
}
temp = nums[i];
nums[i] = nums[mini];
nums[mini] = temp;
}
return nums;
}
}
Editor is loading...
Leave a Comment