static Node rearrangeEvenOdd ( Node head ) {
  if ( head == null ) return null ;
  Node odd = head ;
  Node even = head . next ;
  Node evenFirst = even ;
  while ( true ) {
    if ( odd == null || even == null || ( even . next ) == null ) {
      break ;
    }
    odd . next = even . next ;
    odd = even . next ;
    if ( odd . next == null ) {
      even . next = null ;
      break ;
    }
    even . next = odd . next ;
    even = odd . next ;
  }
  Node current = evenFirst ;
  Node prev = null ;
  Node front = null ;
  while ( current != null ) {
    front = current . next ;
    current . next = prev ;
    prev = current ;
    current = front ;
  }
  evenFirst = prev ;
  odd . next = evenFirst ;
  return head ;
}

static Node rearrangeEvenOdd ( Node head ) { if ( head == null ) return null ; Node odd = head ; Node even = head . next ; Node evenFirst = even ; while ( true ) { if ( odd == null || even == null || ( even . next ) == null ) { break ; } odd . next = even . next ; odd = even . next ; if ( odd . next == null ) { even . next = null ; break ; } even . next = odd . next ; even = odd . next ; } Node current = evenFirst ; Node prev = null ; Node front = null ; while ( current != null ) { front = current . next ; current . next = prev ; prev = current ; current = front ; } evenFirst = prev ; odd . next = evenFirst ; return head ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (null_literal))) consequence: (return_statement (null_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (field_access object: (identifier) field: (identifier)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (true)) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (binary_expression left: (identifier) right: (null_literal)) right: (binary_expression left: (identifier) right: (null_literal))) right: (binary_expression left: (parenthesized_expression (field_access object: (identifier) field: (identifier))) right: (null_literal)))) consequence: (block (break_statement))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (field_access object: (identifier) field: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) consequence: (block (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) (break_statement))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (field_access object: (identifier) field: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (null_literal))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (null_literal))) (while_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (null_literal))) body: (block (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (identifier))) (return_statement (identifier))))