Insertion Sort El ordenamiento por inserción es un algoritmo que ayuda a ordenar un número pequeño de elementos. 1 arr = [5, 3, 4, 8, 7, 5, 1, 2, 3] 2 3 4 5 6 7 8 for j in range(1, len(arr)): actual = arr[j] i = j - 1 while i >= 0 and arr[i] > actual: arr[i+1] = arr[i] i -= 1 arr[i+1] = actual 9 10 11 1 2 print(arr) public class Insertion{ public static void main(String [] args){ int []arr = {5, 3, 4, 8, 7, 5, 1, 2, 3}; 3 4 for(int j=1; j < arr.length; j++){ int actual = arr[j]; 5 6 7 int i = j - 1; while(i >= 0 && arr[i] > actual){ 8 9 arr[i+1] = arr[i]; i--; 10 11 } arr[i+1] = actual; 12 13 } for(int 14 15 System.out.println(elem + " "); 16 } 17 } 18 19 1 2 elem: arr){ } func main(){ arr := []int{5, 3, 4, 6, 7, 5, 1, 2, 3} 3 4 5 for j := 1; j < len(arr); j++{ actual := arr[j] i := j - 1; for i >= 0 && arr[i] > actual{ arr[i+1] = arr[i] i-} arr[i+1] = actual 6 7 8 9 10 11 } fmt.Println(arr) 12 13 14 }