在二叉搜索树中找到第n个节点
Find the nth Node in Binary Search Tree
使用这个bootstrap:
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
,以及一个名为element
的值template <class Comparable>
。
听起来我(从你的评论)像你正在寻找Boost的多索引容器(http://www.boost.org/doc/libs/1_59_0/libs/multi_index/doc/index.html)。您将拥有矢量视图和地图视图,并在使用地图视图按键搜索时使用push_back插入矢量视图。然后,您将使用矢量视图来获取第n个插入的元素。
相关文章:
- C++二叉搜索树模板从函数返回节点
- 二叉搜索树使用最常用的节点来打印出某些语句
- 返回二叉搜索树特定级别的节点数的函数
- 无法打印完整的二叉搜索树,因为我从最低节点向后迭代的逻辑有缺陷
- 使用二进制搜索树中的迭代器对象访问左侧节点
- C++ Eclipse:二叉搜索树节点>数据=变量似乎不起作用
- 删除节点方法实际上不会删除二叉搜索树中的节点.C++
- 在C++中实现二叉搜索树,搜索不起作用.尝试打印节点的元素会导致输出崩溃
- 二叉搜索树按级别递归C++打印节点
- 插入到二叉搜索树中.节点替换
- 如何替换二叉搜索树中的节点
- C++ 从二叉搜索树中删除具有两个子节点的特定节点
- 检查节点是否是二进制搜索树的根
- 在二进制搜索树中删除节点
- 如何从二进制搜索树中删除节点
- 从C++二进制搜索树中删除一个节点(类而非结构)
- 从基于矢量的二叉搜索树中删除节点的最佳方法
- 为什么我的原始二叉搜索树被修改,即使我在另一个节点中复制了根节点
- 为什么这个计算二进制搜索树中节点的递归函数总是返回比预期更大的结果
- 二进制搜索树中的根节点为空