Question

I can't seem to understand what is left and what is right node in tree.

Suppose I have a structure like this,

struct Rect
{
    void visit() { }
    std::vector<Rect*> components;
};

What is left and what is right in here? Is it present here? If so, how can I determine w/c is left and w/c is right?

I want to traverse them from root to parent (post-order)

Is this the right way?

void postorder(Rect *rect)
{
    if (rect == nullptr) return;

    for (auto &i : boost::adaptors::reverse(rect->components))
    {
        postorder(i);
    }

    rect->visit();
}

But left and right node aren't present here?

Was it helpful?

Solution

There is no left and right here (unless your rectangles are sorted by x-axis position, which isn't shown).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top