java在双链表中删除头
我叫马里奥,我有一个问题。如果我有1->;2->;3我想去掉我设置的头。头部=移除的头部。getNextNode()和之后,我只将上一个节点设置为null
public String removeHead()
{
Node removedHead = this.head; // variable for removedHead
if(removedHead ==null)
{
return null;
}
this.head=removedHead.getNextNode(); // get next node to head
if( this.head != null)
{
this.head.setPreviousNode(null); // setting the previous node ==null
}
if(removedHead == this.tail)
{
this.removeTail();
}
return removedHead.data;
}
共 (0) 个答案