Example #1
0
static void
avl_dump(avl_node *n, FILE *fp)
{
    if (n) {
        if (n->link[0])
            fprintf(fp, "\t%ld -> %ld\n", n->key, n->link[0]->key);

        if (n->link[1])
            fprintf(fp, "\t%ld -> %ld\n", n->key, n->link[1]->key);

        avl_dump(n->link[0], fp);
        avl_dump(n->link[1], fp);
    }
}
Example #2
0
static void avl_dump (node* tree, int shift) {
	for (int i = 0; i < shift; i++)
		printf (" ");

	if (!tree) {
		printf ("E\n");
		return;
	}

	printf ("%u : %d\n", tree -> data, tree -> height);
	//printf ("\nL: %10x\tN: %10x | %3d\tR: %10x\n",
	//		tree -> child [left], tree, tree -> data, tree -> child [right]);
	avl_dump (tree -> child [left], shift + shft);
	avl_dump (tree -> child [right], shift + shft);
}
Example #3
0
void
avl_dump(avl_tree *tree, avl_node *node, int level)
{
    char space[1024];
    memset(space, ' ', 1024);
    space[level*4] = 0;  

    if (node == NULL) return;

    avl_dump(tree, node->child[1], level+1);

    printf("%s[%d]\n", space, ((intr*)AVL_DATA(node, tree))->data);

    avl_dump(tree, node->child[0], level+1);
}
Example #4
0
void
avl_dump(avl_tree_t *root, long lvl){

	int i = 0;
	char spacer[1024];
	char *flag;

	for( i = 0; (i < (lvl*8)) && (i < 128); i++){
		spacer[i] = ' ';
	}
	spacer[i] = '\0';

	if( root == NULL ){
		printf("%s[NULL]\n", spacer);
	}else{    

		switch(root->flags){
		case AVL_FLAGS_BALANCED:
			flag="BA";
			break;
		case AVL_FLAGS_LEFT_HEAVY:
			flag="LH";
			break;
		case AVL_FLAGS_RIGHT_HEAVY:
			flag="RH";
			break;
		case AVL_FLAGS_LEFT_UNBAL:
			flag="LU";
			break;
		case AVL_FLAGS_RIGHT_UNBAL:
			flag="RU";
			break;
		default:
			EMSG("Bad Flag\n");
			flag="NO";
		}


		printf("%s[%4lu] ------- depth : %lu flag : %s\n",
		       spacer, root->key, root->depth, flag);
		printf("%s       -LEFT--\n", spacer);
		avl_dump(root->left, lvl+1);
		printf("%s       -RIGHT-\n", spacer);
		avl_dump(root->right, lvl+1);
	}

}
Example #5
0
int avl_dump_tree (head* head)
{
	if (!head) {
		errno = EBADF;
		return -1;
	}

	avl_dump (head -> tree, 0);
	return 0;
}
Example #6
0
static void
avl_dump_to_file(avl_node *n, const char *file)
{
    FILE *fp, rv;

    fp = fopen(file, "w");
    if (fp) {
        fprintf(fp, "digraph G\n{\n");
        fprintf(fp, "node [shape=\"circle\"];\n");
        avl_dump(n, fp);
        fprintf(fp, "}\n");

        fclose(fp);
    }
}