Pre-order Traversal
Lesson 7 of 13 in Coddy's Binary Tree - Data Structures Series #3 course.
Challenge
EasyPre-order traversal:
- Visit the root
- Traverse the left subtree
- Traverse the right subtree
Add to BinaryTree the method preOrderPrint that prints the values in pre-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_preOrderPrint(&bt);
return 0;
}
All lessons in Binary Tree - Data Structures Series #3
2Binary Tree Project
Node ClassNode with Sons