static void reverseQueueFirstKElements ( int k ) {
  if ( queue . isEmpty ( ) == true || k > queue . size ( ) ) return ;
  if ( k <= 0 ) return ;
  Stack < Integer > stack = new Stack < Integer > ( ) ;
  for ( int i = 0 ;
  i < k ;
  i ++ ) {
    stack . push ( queue . peek ( ) ) ;
    queue . remove ( ) ;
  }
  while ( ! stack . empty ( ) ) {
    queue . add ( stack . peek ( ) ) ;
    stack . pop ( ) ;
  }
  for ( int i = 0 ;
  i < queue . size ( ) - k ;
  i ++ ) {
    queue . add ( queue . peek ( ) ) ;
    queue . remove ( ) ;
  }
}

static void reverseQueueFirstKElements ( int k ) { if ( queue . isEmpty ( ) == true || k > queue . size ( ) ) return ; if ( k <= 0 ) return ; Stack < Integer > stack = new Stack < Integer > ( ) ; for ( int i = 0 ; i < k ; i ++ ) { stack . push ( queue . peek ( ) ) ; queue . remove ( ) ; } while ( ! stack . empty ( ) ) { queue . add ( stack . peek ( ) ) ; stack . pop ( ) ; } for ( int i = 0 ; i < queue . size ( ) - k ; i ++ ) { queue . add ( queue . peek ( ) ) ; queue . remove ( ) ; } }
(method_declaration (modifiers) type: (void_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (integral_type) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (true)) right: (binary_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) consequence: (return_statement)) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (decimal_integer_literal))) consequence: (return_statement)) (local_variable_declaration type: (generic_type (type_identifier) (type_arguments (type_identifier))) declarator: (variable_declarator name: (identifier) value: (object_creation_expression type: (generic_type (type_identifier) (type_arguments (type_identifier))) arguments: (argument_list)))) (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 (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (for_statement init: (local_variable_declaration type: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) condition: (binary_expression left: (identifier) right: (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (identifier))) update: (update_expression (identifier)) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))