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

}

1
  • 1
    It separates the method parameters so it's legal Java. Commented Oct 7, 2012 at 11:40

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.