我不确定这一行究竟意味着什么。 任何人都可以好好解释一下(a,n)中的“逗号”究竟做什么吗? (a,n)和(a,minPos,n)有什么区别?选择排序方法Java
* Sorts an array by the "selection sort" method.
* Find the position of the smallest element in the array,
* swap it with the next unsorted element
*
* @param a the array to sort
*/
public static void sort(int[] a)
{
for (int n = 0; n < a.length - 1; n++)
{
int minPos = minimumPosition(a, n);
if (minPos != n)
{
swap(a, minPos, n);
}
}
public static int minimumPosition(int[] a, int from)
{
int minPos = from;
for (int i = from + 1; i < a.length; i++)
{
if (a[i] < a[minPos])
{
minPos = i;
}
}
return minPos;
}
}
它分离方法的参数所以它是合法的Java。 –