Tree: Preorder Traversal

Sort by

recency

|

454 Discussions

|

  • + 0 comments

    My solution in C++

        void preOrder(Node *root) 
        {
            if (root != NULL)
            {
                cout << root->data << " ";
                preOrder(root->left);
                preOrder(root->right);
            }
        }
    
  • + 0 comments

    For many languages in selector it doesn't provide any boilerplate code and cannot be solved by reading input since you don't know how binary tree composed. How can I use hakkerrank to prepare for interview

  • + 0 comments

    In some languages like Kotlin it gives only a main fucntion which doesn't have a Node class. And there's no explanation how the single array, that the input is giving, is sorted... I spent hours trying to figure out what the tree from the input should look like and I was trying to write a function to create the tree with Node class... So then I switched to Java and saw that the node object is given...

  • + 0 comments
    
    

    void solve(Node* root) { if(root == NULL) { return; } cout<data<<" "; solve(root->left); solve(root->right); }

    
    

    solve(root);

    
    
  • + 0 comments

    Why it was showing main method in this?