[英]how to find the number of nodes at level x of the binary search tree ( with restrictions )
[英]Find count of nodes on a specific level of a binary tree (iteratively)
我知道如何遞歸地在樹的級別上計算節點(此答案中的使用技巧https://stackoverflow.com/a/12879973/2663649 ),但是我無法形成迭代算法,並且不確定是否應該使用堆棧或指針數組保存以前的節點(返回到根)。
您可以將遞歸算法轉換為迭代算法。
只需使用執行遞歸的堆棧結構即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.