Tag: binary search tree

二元运算符的错误操作数类型“>”?

我正在写一个BST计划。 我收到错误: “二元运算符的坏操作数类型”>“ 第一种类型:java.lang.Object 第二种类型:java.lang.Object“ 这是它给我错误的方法: public void placeNodeInTree(TreeNode current, TreeNode t) { if(current == null) current = t; else{ if(current.getValue() > t.getValue()) current.setRight(t); if(current.getValue() < t.getValue()) current.setLeft(t); } } getValue()的返回类型为Object,因此是java.lang.Object类型。 这是我第一次见到这个错误。 谁能给我一些关于这个错误的背景知识? 谢谢

这个inorder遍历算法如何工作?

我没有太多的递归经验,所以我很难确定这个算法是如何工作的: public static void inorder(Node n) { if (n != null) { inorder(n.getLeft()); System.out.print(n.data + ” “); inorder(n.getRight()); } } 我知道它访问了树中每个节点的左右子节点,但我无法理解为什么它确实有效。

如何计算二叉搜索树的深度

我想计算二进制搜索树的每个节点的深度的总和。 元素的各个深度尚未存储。

如何在RedBlackTree实现中修复删除?

这是我正在使用的RedBlackTree的实现(来自Mark Allen Weiss,Data Structures public class RedBlackTree<AnyKey extends Comparable, AnyValue extends Comparable> implements MyTreeMap{ private static final int BLACK = 1; private static final int RED = 0; // The psuedo(bogus) root, has a key value of negative infinity and a right link to the real root. private RedBlackNode header; // Used in place of […]