遍历链表,删除元素结点,注意别断链。复杂度O(N)。
public void remove(Item item)
{
while (first != null && item.equals(first.item))
{
first = first.next;
}
Node<Item> current = first;
Node<Item> node;
while (current != null && current.next != null)
{
node = current.next;
if (item.equals(node.item))
{
current.next = node.next;
}
else
{
current = node;
}
}
}
备注:
参考链接](https://blog.csdn.net/furzoom/article/details/52919414)