http://www.cs.arizona.edu/~mercer/Projects/BSTRemoveGeneric.pdf
我在编码时遇到了麻烦!我不知道为什么这不起作用!它让我发疯!!!! OrderedSet 的删除方法。这是我的代码
public boolean remove(E element)
{
if(root == null)
{
return false;
}
if(!contains(element))
{
return false;
}
else if(root.data.equals(element) && root.left != null)
{
root = root.left;
return true;
}
//return remove(element, root);
else
{
TreeNode curr = root;
TreeNode prev = root;
while(element.compareTo(curr.data) != 0 && curr != null)
{
prev = curr;
if(element.compareTo(curr.data) < 0)
{
curr = curr.left;
}
else// if(element.compareTo(curr.data) > 0)
{
curr = curr.right;
}
}
if(curr.left == null)
{
if(curr == prev.left)
{
prev.left = curr.right;
}
else// if(curr == prev.right)
{
prev.right = curr.right;
}
return true;
}
else// if(curr.left != null)
{
OrderedSet<E> temp = new OrderedSet<E>();
temp.root = curr.left;
System.out.println("\n\n\n\n" + curr.data + "\n" + prev.data + "\n" + temp.toStringInorder() + "\n" + temp.max() + "\n\n\n\n");
curr.data = temp.max();
TreeNode ref = curr;
while(curr.right != null)
{
ref = curr;
curr = curr.right;
}
ref = ref.left;
return true;
}
}
错误:
插入 GADC 后删除(“G”)后失败
呼叫十字路口后尺寸失败。
根节点有左子节点时删除根节点失败(
当两者都具有三个相同的元素时,相交失败
删除root失败,右边有更多
插入后删除失败(“M”);插入(“G”);删除(“M”);
您是否使用“==”而不是“等于”?插入后删除失败(新整数(50));插入(新整数(75));删除(新整数(50));
删除期间大小失败(2 次)
(仅显示 9 个提示中的 8 个)