static void maximizeArray ( int [ ] arr , int length , int swaps ) {
  if ( swaps == 0 ) return ;
  for ( int i = 0 ;
  i < length ;
  i ++ ) {
    int max_index = 0 , max = Integer . MIN_VALUE ;
    int limit = ( swaps + i ) > length ? length : swaps + i ;
    for ( int j = i ;
    j <= limit ;
    j ++ ) {
      if ( arr [ j ] > max ) {
        max = arr [ j ] ;
        max_index = j ;
      }
    }
    swaps -= ( max_index - i ) ;
    swapMax ( arr , i , max_index ) ;
    if ( swaps == 0 ) break ;
  }
}

static void maximizeArray ( int [ ] arr , int length , int swaps ) { if ( swaps == 0 ) return ; for ( int i = 0 ; i < length ; i ++ ) { int max_index = 0 , max = Integer . MIN_VALUE ; int limit = ( swaps + i ) > length ? length : swaps + i ; for ( int j = i ; j <= limit ; j ++ ) { if ( arr [ j ] > max ) { max = arr [ j ] ; max_index = j ; } } swaps -= ( max_index - i ) ; swapMax ( arr , i , max_index ) ; if ( swaps == 0 ) break ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (integral_type) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier)) (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement)) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal)) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (ternary_expression condition: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (identifier)) consequence: (identifier) alternative: (binary_expression left: (identifier) right: (identifier))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (identifier))) condition: (binary_expression left: (identifier) right: (identifier)) update: (update_expression (identifier)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (array_access array: (identifier) index: (identifier)) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (array_access array: (identifier) index: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))))) (expression_statement (assignment_expression left: (identifier) right: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))))) (expression_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (break_statement))))))