static Node reverseList ( Node head ) {
  Stack < Node > stk = new Stack < Node > ( ) ;
  Node ptr = head ;
  while ( ptr . next != null ) {
    stk . push ( ptr ) ;
    ptr = ptr . next ;
  }
  head = ptr ;
  while ( ! stk . isEmpty ( ) ) {
    ptr . next = stk . peek ( ) ;
    ptr = ptr . next ;
    stk . pop ( ) ;
  }
  ptr . next = null ;
  return head ;
}

static Node reverseList ( Node head ) { Stack < Node > stk = new Stack < Node > ( ) ; Node ptr = head ; while ( ptr . next != null ) { stk . push ( ptr ) ; ptr = ptr . next ; } head = ptr ; while ( ! stk . isEmpty ( ) ) { ptr . next = stk . peek ( ) ; ptr = ptr . next ; stk . pop ( ) ; } ptr . next = null ; return head ; }
(method_declaration (modifiers) type: (type_identifier) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier))) body: (block (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)))) (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (identifier))) (while_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) body: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (assignment_expression left: (identifier) right: (field_access object: (identifier) field: (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))))) (expression_statement (assignment_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) (return_statement (identifier))))