我尝试通过输入单个值在LinkedList中创建一个删除方法,然后从节点中删除与该值匹配的所有值。
似乎无法解决它。
有什么不对?
public void RemoveByValue(int value)
{
if (start == null)
return;
Node runner = start;
while (runner.Next != null)
{
Node current = FindValue(value);
if (current == null)
{
return;
}
current.Next = runner.Next;
}
}
private Node FindValue(int value)
{
Node runner = start;
while (runner.Next.Value != value)
{
runner = runner.Next;
}
return runner;
}