【发布时间】:2020-12-24 12:33:13
【问题描述】:
我的问题是我的删除方法没有删除我要删除的节点并给我一个无限循环。
public void delete(String name){
Node current = head;
boolean checker = false;
while(current != null && current.name != name && checker != true){
try{
if(current.name.equals(name)){
Node p = current.previous;
Node q = current.next;
/*The code can somehow get through only above this line, below here its not anymore*/
p.next = q;
q.previous = p;
System.out.println("Item successfully deleted.");
checker = true;
}else if(!current.name.equals(name) && current == tail){
System.out.println("Item not found.");
}
current = current.next;
} catch(NullPointerException e){}
}
}
我在这里寻求有关我的问题的提示或提示 (对不起我的英语不好)
【问题讨论】:
-
您是否在输出中找不到项目?
-
不确定这是否是唯一的问题,但在循环标头中,您将
Strings 与==进行比较。 -
你的 catch 程序有一个空的 try 块。除非您真的知道自己在做什么,否则请不要这样做。至少添加 e.printStackTrace() 用于调试目的。
-
这是学习使用调试器的好时机。
标签: java oop doubly-linked-list