Java Selection sort [closed]

2019-10-02 14:46发布

A - an array containing the list of numbers
numItems - the number of numbers in the list

for i = 0 to numItems - 1
    for  j = i+1 to numItems 
        if A[i] > A[j]
            // Swap the entries
            Temp = A[i]
            A[i] = A[j]
            A[j] = Temp  
        End If    
    Next j
Next i\

Can comeone convert this to java for me? I've tried but can't figure it out.

1条回答
在下西门庆
2楼-- · 2019-10-02 15:23
 public static void selectionSort1(int[] x) {
    for (int i=0; i<x.length-1; i++) {
        for (int j=i+1; j<x.length; j++) {
            if (x[i] > x[j]) {
                // Exchange elements
                int temp = x[i];
                x[i] = x[j];
                x[j] = temp;
            }
        }
    }
}
查看更多
登录 后发表回答