Reverse Breadth First traversal in C#

后端 未结 2 1595
无人及你
无人及你 2021-02-04 05:09

Anyone has a ready implementation of the Reverse Breadth First traversal algorithm in C#?

By Reverse Breadth First traversal , I mean instead of searching a tree startin

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 05:36

    Use a combination of a stack and queue.

    Do the 'normal' BFS using the queue (which I presume you know to do already), and keep pushing nodes on the stack as you encounter them.

    Once done with the BFS, the stack will contain the reverse BFS order.

提交回复
热议问题