The interviewer looked bubble sort I wrote let me go back to such notice

A trip to Wal-Mart interview, let the interviewer to do a pen questions, very simple, that is, a disordered array of int (int []), write tools to sort, so I wrote a bubble sort:

    public static int[] sort(int[] arr) {
        if (arr == null || arr.length == 0) return arr;
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        return arr;
    }

 

Finished, looked the interviewer said: You first go back to such notice it!

TMD, there is no communication, directly to leave, go back and I deliberately ran the program several times, no problem ah! Where written wrong?

 

Guess you like

Origin www.cnblogs.com/jun1019/p/10932042.html