• + 5 comments

    Simple version.

    void top_view(node* root, int order = 0) {
        if (root == NULL) return;
        if (order <= 0) top_view(root->left, -1);
        cout << root->data << " ";
        if (order >= 0) top_view(root->right, 1);
    }