static int getLevel ( node root , int data ) {
  Queue < node > q = new LinkedList < > ( ) ;
  int level = 1 ;
  q . add ( root ) ;
  q . add ( null ) ;
  while ( ! q . isEmpty ( ) ) {
    node temp = q . poll ( ) ;
    if ( temp == null ) {
      if ( q . peek ( ) != null ) {
        q . add ( null ) ;
      }
      level += 1 ;
    }
    else {
      if ( temp . data == data ) {
        return level ;
      }
      if ( temp . left != null ) {
        q . add ( temp . left ) ;
      }
      if ( temp . right != null ) {
        q . add ( temp . right ) ;
      }
    }
  }
  return 0 ;
}

static int getLevel ( node root , int data ) { Queue < node > q = new LinkedList < > ( ) ; int level = 1 ; q . add ( root ) ; q . add ( null ) ; while ( ! q . isEmpty ( ) ) { node temp = q . poll ( ) ; if ( temp == null ) { if ( q . peek ( ) != null ) { q . add ( null ) ; } level += 1 ; } else { if ( temp . data == data ) { return level ; } if ( temp . left != null ) { q . add ( temp . left ) ; } if ( temp . right != null ) { q . add ( temp . right ) ; } } } return 0 ; }
(method_declaration (modifiers) type: (integral_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (type_identifier) name: (identifier)) (formal_parameter type: (integral_type) 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: (integral_type) declarator: (variable_declarator name: (identifier) value: (decimal_integer_literal))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))) (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (null_literal)))) (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)))) (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (null_literal))) consequence: (block (if_statement condition: (parenthesized_expression (binary_expression left: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list)) right: (null_literal))) consequence: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (null_literal)))))) (expression_statement (assignment_expression left: (identifier) right: (decimal_integer_literal)))) alternative: (block (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (identifier))) consequence: (block (return_statement (identifier)))) (if_statement condition: (parenthesized_expression (binary_expression left: (field_access object: (identifier) field: (identifier)) right: (null_literal))) consequence: (block (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: (block (expression_statement (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (field_access object: (identifier) field: (identifier))))))))))) (return_statement (decimal_integer_literal))))