Beispiel #1
0
void print_inorder_helper(tnode_t* tree) {
    //Stop when we reach the edge
    if(tree == NULL)
        return;

    //Print left part of tree
    print_inorder_helper(tree->lchild);

    //Print value of current node
    printf("%d ", tree->data);

    //Print right part of tree
    print_inorder_helper(tree->rchild);
}
void print_inorder_helper(bst * root, int isRoot, int * isFirst) {
	if(is_empty(root)) {
		return;
	}
	print_inorder_helper(root->left, 0, isFirst);
	if(!*isFirst) {
		printf(", ");
	} else {
		*isFirst = 0;
	}
	printf("%d->%d", root->key, root->value);
	print_inorder_helper(root->right, 0, isFirst);

	if(isRoot) {
		printf("\n");
	}
}
Beispiel #3
0
void print_inorder(tnode_t* tree) {
    print_inorder_helper(tree);
    printf("\n");
}
void print_inorder(bst * root) {
	int isFirst = 1;
	print_inorder_helper(root, 1, &isFirst);
}