static void PrintLeafLeftToRight ( Node root ) {
  Stack < Node > s1 = new Stack < > ( ) ;
  Stack < Node > s2 = new Stack < > ( ) ;
  ;
  s1 . push ( root ) ;
  while ( ! s1 . empty ( ) ) {
    Node curr = s1 . peek ( ) ;
    s1 . pop ( ) ;
    if ( curr . left != null ) s1 . push ( curr . left ) ;
    if ( curr . right != null ) s1 . push ( curr . right ) ;
    else if ( curr . left == null && curr . right == null ) s2 . push ( curr ) ;
  }
  while ( ! s2 . empty ( ) ) {
    System . out . print ( s2 . peek ( ) . data + " " ) ;
    s2 . pop ( ) ;
  }
}

static void PrintLeafLeftToRight ( Node root ) { Stack < Node > s1 = new Stack < > ( ) ; Stack < Node > s2 = new Stack < > ( ) ; ; s1 . push ( root ) ; while ( ! s1 . empty ( ) ) { Node curr = s1 . peek ( ) ; s1 . pop ( ) ; if ( curr . left != null ) s1 . push ( curr . left ) ; if ( curr . right != null ) s1 . push ( curr . right ) ; else if ( curr . left == null && curr . right == null ) s2 . push ( curr ) ; } while ( ! s2 . empty ( ) ) { System . out . print ( s2 . peek ( ) . data + " ▁ " ) ; s2 . pop ( ) ; } }
(method_declaration (modifiers) type: (void_type) 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)) arguments: (argument_list)))) (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)) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (local_variable_declaration type: (type_identifier) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list))) (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier)))))) (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier))))) alternative: (if_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal)) right: (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal)))) consequence: (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))))) (while_statement condition: (parenthesized_expression (unary_expression operand: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))) body: (block (expression_statement (method_invocation object: (field_access object: (identifier) field: (identifier)) name: (identifier) arguments: (argument_list (binary_expression left: (field_access object: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) field: (identifier)) right: (string_literal))))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)))))))