• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 02, 2022 |450 Views
Level order traversal line by line | Set 2 (Using Two Queues)
  Share   Like
Description
Discussion

a different approach using two queues is discussed. We can insert the first level in first queue and print it and while popping from the first queue insert its left and right nodes into the second queue. Now start printing the second queue and before popping insert its left and right child nodes into the first queue. Continue this process till both the queues become empty.

Level order traversal line by line  Set 2 (Using Two Queues): https://www.geeksforgeeks.org/level-order-traversal-line-line-set-2-using-two-queues/

Read More