提问人:TorusWithSprinkles 提问时间:4/20/2021 更新时间:4/20/2021 访问量:166
仅使用节点的键从二叉搜索树中删除节点
Deleting a node from a Binary Search Tree using only a node's key
问:
我正在添加一些函数/使用使用二叉搜索树的预先编写的程序(客户帐户数据库),并且我正在尝试弄清楚这种删除方法的工作原理和原因:
public void deleteCustomer()
{
System.out.println("Enter the account number of the customer to be removed.");
String accountNumber = userInput.next();
try {
records.remove(new CustomerAccount(accountNumber));
}
catch(ElementNotFoundException e) {
System.out.println("There is no account with that number.");
}
}
其中 是包含字段的对象,并且是 BST。记录的功能如下所示:CustomerAccount
accountNumber
records
remove
public boolean remove(E target) {
return delete(target) != null;
}
并以递归方式调用 BST 的标准查找函数。但我的问题是,这条线到底发生了什么?delete
records.remove(new CustomerAccount(accountNumber));
它正在使用新的 CustomerAccount 调用该方法?这里到底发生了什么?这是处理这种情况的标准方法吗?我从未见过这样的东西,但我不喜欢使用数据结构,所以我不确定。任何帮助或澄清都会很棒,谢谢!
答: 暂无答案
评论