Exemplo n.º 1
0
// Recursive version of getHeight() that traverses the tree and counts the height.
// Could have implemented both as one function if getHeight() weren't inherited.
int Node::get_max_height(Node* current) {
	int left_height, right_height, height;

	// Recursively count up the left and right heights of each node,
	// then returns the max to be added to the parent.
	left_height = current->left_child ? get_max_height(current->left_child) + 1 : 0;
	right_height = current->right_child ? get_max_height(current->right_child) + 1 : 0;
	height = max(left_height, right_height);

	return height;
}
Exemplo n.º 2
0
int Node::get_balance() {
	int balance, left_height, right_height;

	// Find the right and left height of a node
	left_height = left_child ? get_max_height(left_child) + 1 : 0;
	right_height = right_child ? get_max_height(right_child) + 1 : 0;

	// Convert the heights to the balance (for deciding if the tree needs rearranging)
	balance = right_height - left_height;

	return balance;
}
Exemplo n.º 3
0
// Returns the length of the longest path from the node to one of its leaves.
int Node::getHeight() {
	int height, left_height, right_height;

	// Get the left and right heights from the root
	left_height = left_child ? get_max_height(left_child) : 0;
	right_height = right_child ? get_max_height(right_child) : 0;

	// Find the maximum
	height = max(left_height, right_height);

	return height;
}
Exemplo n.º 4
0
css_error css__compose_max_height(const css_computed_style *parent,
		const css_computed_style *child,
		css_computed_style *result)
{
	css_fixed length = 0;
	css_unit unit = CSS_UNIT_PX;
	uint8_t type = get_max_height(child, &length, &unit);

	if (type == CSS_MAX_HEIGHT_INHERIT) {
		type = get_max_height(parent, &length, &unit);
	}

	return set_max_height(result, type, length, unit);
}
Exemplo n.º 5
0
void Tetris::print() const {
    
    std::cout << std::endl;
    
    // This Tetris member function returns the height of the tallest
    // column on the board
    int max_height = get_max_height();
    
    // print each row of the board, from top to bottom
    for (int h = max_height-1; h >= 0; h--) {
        for (int w = 0; w < width; w++) {
            if (h < heights[w]) {
                std::cout << data[w][h];
            } else {
                // print a blank if this column is shorter than the current height
                std::cout << ' ';
            }
        }
        std::cout << std::endl;
    }
    
    // print a horizontal bar of appropriate length at the bottom of the board
    std::cout << std::string (width,'-') << std::endl;
    
    // print out the column height,
    // if the height is 2 digits, print them vertically
    
    // this only works for a maximum of 99 rows!
    assert (max_height <= 99);
    
    // print out the tens digit (if necessary)
    if (max_height > 9) {
        for (int w = 0; w < width; w++) {
            if (heights[w] > 9)
                std::cout << heights[w]/10;
            else
                std::cout << ' ';
        }
        std::cout << std::endl;
    }
    
    // print out the ones digit
    for (int w = 0; w < width; w++) {
        std::cout << heights[w]%10;
    }
    
    std::cout << std::endl << std::endl;
}
Exemplo n.º 6
0
declaration mk_theorem(environment const & env, name const & n, level_param_names const & params, expr const & t, expr const & v) {
    unsigned h = get_max_height(env, v);
    return declaration(new declaration::cell(n, params, t, true, v, h+1, true));
}
Exemplo n.º 7
0
declaration mk_definition(environment const & env, name const & n, level_param_names const & params, expr const & t,
                          expr const & v, bool use_conv_opt) {
    unsigned h = get_max_height(env, v);
    return mk_definition(n, params, t, v, h+1, use_conv_opt);
}