Question: We have seen several tree traversals for Binary Trees: in - order, pre - order, and post - order. Another to consider is Level Order

We have seen several tree traversals for Binary Trees: in-order, pre-order, and post-order. Another to consider is Level Order Traversal of a tree. This is a Breadth-First search through the tree, where we visit the nodes in the tree by level from left to right.
Modify your existing template Binary Search Tree class to support a Level Order Traversal.
void Levelorder(ostream& out); A function to output the level-order traversal of the tree with a space between each value
The main function will take as input the integer values to a add to the tree. Your class should insert the values into the tree then output a level-order traversal. **Note: You will need to implement a Queue. **
For example, if the input is:
5734682
We would have the tree:
5<-- Level 0
/\
/\
37<-- Level 1
/\/\
2468<-- Level 2
The traversal should be:
Level-Order Traversal
5
37
2468

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!