Menu
Coddy logo textTech

Post-order Traversal

Lesson 9 of 13 in Coddy's Binary Tree - Data Structures Series #3 course.

challenge icon

Challenge

Easy

Post-order traversal:

  1. Traverse the left subtree
  2. Traverse the right subtree
  3. Visit the root

Add to BinaryTree the method postOrderPrint that prints the values in post-order, each followed by a space.

Try it yourself

#include <stdio.h>
#include <string.h>
#include "binarytree.h"

int main() {
    char buf[4096];
    if (!fgets(buf, sizeof(buf), stdin)) buf[0] = '\0';
    buf[strcspn(buf, "\r\n")] = '\0';
    BinaryTree bt;
    BinaryTree_init(&bt);
    BinaryTree_buildTree(&bt, buf);
    BinaryTree_postOrderPrint(&bt);
    return 0;
}

All lessons in Binary Tree - Data Structures Series #3