int pre_visit(tree* t, int n) { if(!t) { return 0; } int f_res = 0; if (t->x >= n) { n = t->x; ++f_res; } return f_res + pre_visit(t->l,n) + pre_visit(t->r,n); }
void BaseRenderer::render(Scene& scene) { on_start_render(scene); //FIXME: This is ugly and inconsistent scene.active_camera().apply(&modelview().top()); kmMat4Assign(&projection().top(), &scene.active_camera().projection_matrix()); for(Scene::iterator it = scene.begin(); it != scene.end(); ++it) { Object& object = static_cast<Object&>(*it); if(pre_visit(object)) { (*this)(object); post_visit(object); } } //Reset the modelview and projection for the overlay kmMat4Identity(&modelview().top()); kmMat4Identity(&projection().top()); /* Once the entire scene has been rendered, it's time to handle the overlays. */ for(uint32_t i = 0; i < scene.overlay_count(); ++i) { Overlay& overlay = scene.overlay_ordered_by_zindex(i); projection().push(); for(Scene::iterator it = overlay.begin(); it != overlay.end(); ++it) { Object& object = static_cast<Object&>(*it); if(pre_visit(object)) { (*this)(object); post_visit(object); } } projection().pop(); } on_finish_render(scene); }
int solution(tree * T) { return pre_visit(T, T->x); }