Int n = arr.length; For (int i = 0; i < n – 1; i++) { Int maxIndex = i; For (int j = i + 1; j < n; j++) { If (arr[j] > arr[maxIndex]) { maxIndex = j; } } If (maxIndex ¡= i) { Swap(arr, i, maxIndex); } } }
Public static void main(String[] args) {
Int[] nums = {5, 3, 8, 1, 2, 7, 4, 10, 6, 9}; sortArray(nums); System.out.println(“Arreglo ordenado de mayor a menor:”); For (int num : nums) { System.out.print(num + “ “); } } }