Write a program to print Level Order Traversal in spiral form of a binary tree
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
The solution will, of course, surround basic level order traversal. The spiral order means - It will go from left to right for one level, then right to left for next level and again left to right for the next one and so on.
We need to modify our basic level order traversal.
We can do the flipping of direction (left → right then right → left so on ...) by keeping a flag variable which will be updated at end of each level.
Pre-requisite: Root to tree
Example with Explanation:
C++ implementation:
Output