January 03, 2025 |610 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/