0

I am not sure what this line exactly means. Could anyone kindly explain what "comma" in (a, n) does exactly, please ? Also what is the difference between (a, n) and (a, minPos, n)?

 * 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;
}

}

4

2 回答 2

1

(a,n) means a and n are arguments to the method call minimumPosition(int[] a, int from) similar is the meaning of (a, minPos, n) I explained from a basic view point hope this is what you wanted to know

于 2012-10-07T11:41:19.853 回答
1

By using (a,n) in

    minimumPosition(a, n);

You are passing value of a and n to method

    public static int minimumPosition(int[] a, int from)

.a will be passed to the first argument of method minimumPosition and value of n will be passed to second argument

于 2012-10-07T11:49:15.237 回答