public class Solution {
/**
* @param A an integer array
* @return void
*/
public void sortIntegers(int[] A) {
// Write your code here
if (A == null || A.length <= 1) {
return;
}
for (int left = 0; left < A.length - 1; left++) {
for (int right = left + 1; right < A.length; right++) {
if (A[right] < A[left]) {
swap(A, left, right);
}
}
}
}
private void swap(int[] A, int left, int right) {
int temp = A[left];
A[left] = A[right];
A[right] = temp;
}
}
No comments:
Post a Comment