[英]Find the nth Node in Binary Search Tree
使用此引導程序:
template <class Comparable>
const Comparable& AugmentedBinarySearchTree<Comparable>::NthElement(int n)
{
int *i = 0;
return NthElement(root, i, n)->element;
}
您如何使用nodesVisited
指針在BST中找到第n個節點來跟蹤已檢查的節點?
template <class Comparable>
BinaryNode<Comparable>* AugmentedBinarySearchTree<Comparable>::
NthElement(BinaryNode<Comparable> *t, int *nodesVisited, int n) const
{
}
在BST每個節點都有一個指針left
和right
和的值template <class Comparable>
稱為element
。
(根據您的評論)對我來說,就像您在尋找Boost的多索引容器( http://www.boost.org/doc/libs/1_59_0/libs/multi_index/doc/index.html )。 您將擁有矢量視圖和地圖視圖,並使用push_back插入到矢量視圖中,同時使用地圖視圖按鍵進行搜索。 然后,您將使用矢量視圖獲取第n個插入的元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.