SDE Path

Introduction to Binary Trees

Easy

Introduction to Binary Trees

Implement a binary tree structure with basic node insertion.

Input format

The first line contains level-order tokens representing the tree, where N denotes a null node.

Output format

Print level-order traversal of the tree, space-separated (nulls skipped).

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
1 2 3 4 5 N 6
Expected output
1 2 3 4 5 6
Example 2
Input
1
Expected output
1