コード例 #1
0
int _print_t(ABP tree, int is_left, int offset, int depth, char s[20][255])
{
	char b[20];
	int width = 5;

	if (!tree) return 0;

	sprintf(b, "(%03d)", tree->num);

	int left = _print_t(tree->esq, 1, offset, depth + 1, s);
	int right = _print_t(tree->dir, 0, offset + left + width, depth + 1, s);

#ifdef COMPACT
	for (int i = 0; i < width; i++)
		s[depth][offset + left + i] = b[i];

	if (depth && is_left) {

		for (int i = 0; i < width + right; i++)
			s[depth - 1][offset + left + width / 2 + i] = '-';

		s[depth - 1][offset + left + width / 2] = '.';

	}
	else if (depth && !is_left) {

		for (int i = 0; i < left + width; i++)
			s[depth - 1][offset - width / 2 + i] = '-';

		s[depth - 1][offset + left + width / 2] = '.';
	}
#else
	for (int i = 0; i < width; i++)
		s[2 * depth][offset + left + i] = b[i];

	if (depth && is_left) {

		for (int i = 0; i < width + right; i++)
			s[2 * depth - 1][offset + left + width / 2 + i] = '-';

		s[2 * depth - 1][offset + left + width / 2] = '+';
		s[2 * depth - 1][offset + left + width + right + width / 2] = '+';

	}
	else if (depth && !is_left) {

		for (int i = 0; i < left + width; i++)
			s[2 * depth - 1][offset - width / 2 + i] = '-';

		s[2 * depth - 1][offset + left + width / 2] = '+';
		s[2 * depth - 1][offset - width / 2 - 1] = '+';
	}
#endif

	return left + width + right;
}
コード例 #2
0
ファイル: avl_ex.c プロジェクト: renlord/ethz-aos2015
int _print_t(struct avl_node *tree, avl_type tree_type, int is_left, int offset, int depth, char s[20][255*4])
{
    char b[32];
    int width = 24;

    if (!tree) return 0;
    /* DEPRECATED
     * Left for reference purposes.
     struct addr_mapping *m = tree->mapping;
     addr_t key = tree->type == P_TO_V ? m->paddr : m->vaddr;
     addr_t val = tree->type == P_TO_V ? m->vaddr : m->paddr;
     sprintf(b, "%08lx -> %08lx (%i)", key, val, tree->height);
     */
    struct addr_mapping *m = tree->mapping;
    addr_t key = tree_type == P_TO_V ? m->paddr : m->vaddr;
    addr_t val = tree_type == P_TO_V ? m->vaddr : m->paddr;
    sprintf(b, "%08lx -> %08lx (%i)", key, val, tree->height);

    int left  = _print_t(tree->left,  tree_type, 1, offset,                depth + 1, s);
    int right = _print_t(tree->right, tree_type, 0, offset + left + width, depth + 1, s);


    for (int i = 0; i < width; i++)
        s[2 * depth][offset + left + i] = b[i];

    if (depth && is_left) {

        for (int i = 0; i < width + right; i++)
            s[2 * depth - 1][offset + left + width/2 + i] = '-';

        s[2 * depth - 1][offset + left + width/2] = '+';
        s[2 * depth - 1][offset + left + width + right + width/2] = '+';

    } else if (depth && !is_left) {

        for (int i = 0; i < left + width; i++)
            s[2 * depth - 1][offset - width/2 + i] = '-';

        s[2 * depth - 1][offset + left + width/2] = '+';
        s[2 * depth - 1][offset - width/2 - 1] = '+';
    }
    return left + width + right;
}
コード例 #3
0
void print_t(ABP tree)
{
	char s[20][255];
	for (int i = 0; i < 20; i++)
		sprintf(s[i], "%80s", " ");

	_print_t(tree, 0, 0, 0, s);

	for (int i = 0; i < 20; i++)
		printf("%s\n", s[i]);
}
コード例 #4
0
ファイル: avl_ex.c プロジェクト: renlord/ethz-aos2015
void print_t(struct avl_node *tree, avl_type tree_type)
{
    char s[20][255*4];
    for (int i = 0; i < 20; i++)
        sprintf(s[i], "%80s", " ");

    _print_t(tree, tree_type, 0, 0, 0, s);

    for (int i = 0; i < 20; i++)
        printf("%s\n", s[i]);
}