Skip to content

Preorder traversal in RedBlackBST is incorrect #3045

@Golden-Pigeon

Description

@Golden-Pigeon

In the class com.thealgorithms.datastructures.trees.RedBlackBST, the preorder traversal is

public void printTreepre(Node node) {
    if (node == nil) {
        return;
    }
    System.out.print(
         ((node.color == R) ? " R " : " B ") + "Key: " + node.key + " Parent: " + node.p.key + "\n");
    printTree(node.left);
    printTree(node.right);
}

Should the last two lines call printTreepre rather than printTree?
printTree is an inorder traversal method.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions