walkccc / CLRS

📚 Solutions to Introduction to Algorithms Third Edition
https://walkccc.me/CLRS
MIT License
4.62k stars 1.25k forks source link

Update 10.4.md #500

Closed natjms closed 2 months ago

natjms commented 3 months ago

The original solution seems to treat the argument as both a node and the complete tree, and the way its used is inconsistent with how a binary tree is defined in 10.4. This modification introduces a PRINT-BINARY-TREE-AUX following the same form of the original solution, except that the argument is explicitly a node and not a binary tree.

Complete new solution:

PRINT-BINARY-TREE(T)
    PRINT-BINARY-TREE-AUX(T.root)

PRINT-BINARY-TREE-AUX(node)
    if node != NIL
        PRINT-BINARY-TREE-AUX(node.left)
        print node.key
        PRINT-BINARY-TREE-AUX(node.right)
walkccc commented 2 months ago

Thank you!