Tree: Preorder Traversal

  • + 0 comments

    C++ O(n)

    an elegant way to write it is by using recursion:

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