Question
The Problem: write a program that prints a level-order traversal of each tree. In this problem, each node of a binary tree contains a positive
The Problem:
write a program that prints a level-order traversal of each tree. In this problem, each node of a binary tree contains a positive integer and all binary trees have fewer than 256 nodes.
In a level-order traversal of a tree, the data in all nodes at a given level are printed in left-to-right order and all nodes at level k are printed before all nodes at level k+1.
For this problem, each binary tree is specified by a sequence of pairs (n, s) where n is the value at the node whose path from the root is given by the string s. A path is given by a sequence of L's and R's where L indicates a left branch and R indicates a right branch.
The Output:
For each completely specified binary tree in the input file, the level order traversal of that tree should be printed. If a tree is not completely specified, i.e., some node in the tree is NOT given a value or a node is given a value more than once, then the string ``NOT complete'' should be printed. Output should be stored in a file named op.out.
Sample Input
(6,L) (7,R)
(4,LL) (1,RR) (5,) ()
(9,L) (10,R) ()
Sample Output
5 6 7 4 1
NOT complete
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started