我有一个名为 findNode 的函数,它接收数据并返回链表中的节点。
//helper function that finds the nodes
private ListNode findNode(E toFind){
ListNode current = front;
while(current!=null){
if(toFind.equals(current.data)){
return current;
}
else{
current = current.next;
}
}
return null;
}
我如何使用它来删除节点?
最佳答案
你可以尝试这样的事情:
查找 next
值为 Node
的 Node
,该值是查找结果,然后更新这些节点之间的链接,例如:
//iterate over List
if(current.next = resultOfFindNode){
//exit loop
}
//outside of loop
current.setNext(resultOfFindNode.next);
关于java - 如何用这个函数删除java中单链表中的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30576996/