static Node reverse ( Node head ) {
  if ( head == null ) return null ;
  Node new_head = null ;
  Node last = head . prev ;
  Node curr = last , prev ;
  while ( curr . prev != last ) {
    prev = curr . prev ;
    new_head = insertEnd ( new_head , curr ) ;
    curr = prev ;
  }
  new_head = insertEnd ( new_head , curr ) ;
  return new_head ;
}

static Node reverse ( Node head ) { if ( head == null ) return null ; Node new_head = null ; Node last = head . prev ; Node curr = last , prev ; while ( curr . prev != last ) { prev = curr . prev ; new_head = insertEnd ( new_head , curr ) ; curr = prev ; } new_head = insertEnd ( new_head , curr ) ; return new_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: (null_literal))) (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)) declarator: (variable_declarator name: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (identifier))) body: (block (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation name: (identifier) arguments: (argument_list (identifier) (identifier))))) (return_statement (identifier))))