Challenge: Print Pre-Order Traversal

Let’s print the pre-order traversal of a tree.

Problem

Given a binary tree, perform a pre-order traversal by completing the PrintPreOrder() function. A pre-order traversal is a traversal in which a node is visited first, then its left child, and finally its right child.

Input

A binary tree.

Output

Display pre-order traversal of the tree on the console.

Sample input

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.