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.
Tree: Preorder Traversal
Tree: Preorder Traversal
+ 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 comments JavaScript
if(!root) return; process.stdout.write(`${root.data} `); if(root.left) preOrder(root.left); if(root.right) preOrder(root.right);
+ 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 comments void preOrder( struct node *root) { if(root == NULL) return; printf("%d\t",root->data); preOrder(root->left); preOrder(root->right); return; }
+ 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.
Load more conversations
Sort 415 Discussions, By:
Please Login in order to post a comment