tree.c 606 B

1234567891011121314151617181920212223242526272829
  1. #include <stdlib.h>
  2. #include "tree.h"
  3. /* DO NOT MODIFY THIS FUNCTION!!! */
  4. void Huff_postOrderPrint(HuffNode *tree)
  5. {
  6. // Base case: empty subtree
  7. if (tree == NULL) {
  8. return;
  9. }
  10. // Recursive case: post-order traversal
  11. // Visit left
  12. printf("Left\n");
  13. Huff_postOrderPrint(tree->left);
  14. printf("Back\n");
  15. // Visit right
  16. printf("Right\n");
  17. Huff_postOrderPrint(tree->right);
  18. printf("Back\n");
  19. // Visit node itself (only if leaf)
  20. if (tree->left == NULL && tree->right == NULL) {
  21. printf("Leaf: %c\n", tree->value);
  22. }
  23. }