public static int kthSmallest ( Integer [ ] arr , int l , int r , int k ) {
  if ( k > 0 && k <= r - l + 1 ) {
    int pos = partition ( arr , l , r ) ;
    if ( pos - l == k - 1 ) return arr [ pos ] ;
    if ( pos - l > k - 1 ) return kthSmallest ( arr , l , pos - 1 , k ) ;
    return kthSmallest ( arr , pos + 1 , r , k - pos + l - 1 ) ;
  }
  return Integer . MAX_VALUE ;
}

public static int kthSmallest ( Integer [ ] arr , int l , int r , int k ) { if ( k > 0 && k <= r - l + 1 ) { int pos = partition ( arr , l , r ) ; if ( pos - l == k - 1 ) return arr [ pos ] ; if ( pos - l > k - 1 ) return kthSmallest ( arr , l , pos - 1 , k ) ; return kthSmallest ( arr , pos + 1 , r , k - pos + l - 1 ) ; } return Integer . MAX_VALUE ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (array_type element: (type_identifier) dimensions: (dimensions)) name: (identifier)) (formal_parameter type: (integral_type) 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: (binary_expression left: (identifier) right: (decimal_integer_literal)) right: (binary_expression left: (identifier) right: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (decimal_integer_literal))))) consequence: (block (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (identifier))))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (return_statement (array_access array: (identifier) index: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (binary_expression left: (identifier) right: (decimal_integer_literal)))) consequence: (return_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier))))) (return_statement (method_invocation name: (identifier) arguments: (argument_list (identifier) (binary_expression left: (identifier) right: (decimal_integer_literal)) (identifier) (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier)) right: (decimal_integer_literal))))))) (return_statement (field_access object: (identifier) field: (identifier)))))