public class SelectSort
{
public void selectSort(int[] data, boolean isDesc)
{
for(int i = 0; i < data.length - 1; i++)
{
int temp = i;
for(int j = i+1; j< data.length; j++)
{
if((isDesc == false)&&(data[j] < data[temp]))
{
temp = j;
}
if((isDesc == true)&&(data[j] > data[temp]))
{
temp = j;
}
}
swap(data, i, temp);
}
}
private void swap(int[] data, int m, int n)
{
int temp = data[m];
data[m] = data[n];
data[n] = temp;
}
}
Select Sort
最新推荐文章于 2023-06-06 15:58:49 发布