We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Data Structures
  3. Trees
  4. Tree : Top View
  5. Discussions

Tree : Top View

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • sadesh 6 years ago+ 0 comments
    void top_view(Node root)
    {
    
        if(root != null) {
    
            top_view(root.left, true);
    
            System.out.print(root.data + " ");
    
            top_view(root.right, false);
    
        }
    
    }
    
    void top_view(Node node, boolean goLeft) {
    
        if(node != null) {
            if(goLeft) {
                top_view(node.left, goLeft);
                System.out.print(node.data + " ");
            } else {
                System.out.print(node.data + " ");
                top_view(node.right, goLeft);
            }
        } 
    
    }
    
    27|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature