Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java binart tree print

 public void printTree(){
        int height = maxHeight(root);
        for(int i = 0;i < height;i++){
            printLevel(root, i);
        }

    }

    private void printLevel(Node node, int level){
        if(node == null){
            return;
        }

        if(level == 0){
            System.out.println(node.value+" ");
        }else{
            printLevel(node.left, level - 1);
            printLevel(node.right, level -1);
        }
    }


    private int maxHeight(Node root){
        if(root == null){
            return 0;
        }
        return 1+Math.max(maxHeight(root.left), maxHeight(root.right));
    }
Comment

PREVIOUS NEXT
Code Example
Java :: find minimum number in java 
Java :: how to find length of array in java 
Java :: java run cmd 
Java :: java wait(timeout) 
Java :: how to delete character in string java 
Java :: start async task android 
Java :: Java Writer Using FileWriter 
Java :: java 2d array length 
Java :: java repository sql find not in list 
Java :: how to clear text fields in java 
Java :: initialize hashmap with values 
Java :: map java 
Java :: how to find palindrome numbers in java 
Java :: calculate time java 
Java :: loop through java object 
Java :: how to get color from a hex string in android studio 
Java :: java map string to list 
Java :: pyramid pattern program in java 
Java :: 2d array java 
Java :: check first character of string is number java 
Java :: declaration of an array in java 
Java :: How do you count characters in a string array in Java? 
Java :: imageview.setbackground 
Java :: java explicit array declaration 
Java :: quarkus maven skip test 
Java :: print double without decimal java 
Java :: string.indexof java 
Java :: selection sort java 
Java :: java arraylist with double 
Java :: java structure example 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =