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.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Data Structures
  3. Trees
  4. Tree: Preorder Traversal
  5. Discussions

Tree: Preorder Traversal

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 415 Discussions, By:

recency

Please Login in order to post a comment

  • himanshuprincej1
    1 month ago+ 0 comments

    Java 8 solution :- Recursive Approach

    public static void preOrder(Node root) {
            if(root == null){
                return;
            }
            System.out.print(root.data+" ");
            preOrder(root.left);
            preOrder(root.right);
        }
    
    0|
    Permalink
  • shashinp1996
    3 months ago+ 0 comments

    JavaScript

    if(!root) return;
        process.stdout.write(`${root.data} `);
        if(root.left) preOrder(root.left);
        if(root.right) preOrder(root.right);
    
    0|
    Permalink
  • awittscience
    3 months ago+ 0 comments

    Basic recursive approach in C

    void preOrder( struct node *root) {
        if (root != NULL) {
            printf("%d ", root->data);
            preOrder(root->left);
            preOrder(root->right);
        }
    }
    
    0|
    Permalink
  • srakshitha296
    3 months ago+ 0 comments

    void preOrder( struct node *root) { if(root == NULL) return; printf("%d\t",root->data); preOrder(root->left); preOrder(root->right); return; }

    -1|
    Permalink
  • BruteForce_03
    3 months ago+ 0 comments

    i have'nt got 10 point i had solved all the three traversal even though i have'nt got 30 point. please @hackerrank look upon that.

    0|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy