Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#使用base中的LinkedList数据结构_C#_Algorithm_Data Structures_Linked List_Nodes - Fatal编程技术网

C#使用base中的LinkedList数据结构

C#使用base中的LinkedList数据结构,c#,algorithm,data-structures,linked-list,nodes,C#,Algorithm,Data Structures,Linked List,Nodes,我目前正在学习剑桥数据结构书,每次我想到一个问题,在我看到解决方案之前,我都会试图解决它。 我对RemoveLast()有问题 我的代码中有什么问题?伙计们 考虑循环条件: while (runner != end) 在循环结束时,runner等于end。所以您基本上是将end.Next设置为null并将end设置为自身 您需要在结束节点之前到达该节点 将循环条件更改为: while (runner.Next != end) 这将确保在循环结束时,runner将恰好位于end节点之前 还请注

我目前正在学习剑桥数据结构书,每次我想到一个问题,在我看到解决方案之前,我都会试图解决它。 我对
RemoveLast()有问题


我的代码中有什么问题?伙计们

考虑循环条件:

while (runner != end)
在循环结束时,
runner
等于
end
。所以您基本上是将
end.Next
设置为
null
并将
end
设置为自身

您需要在
结束
节点之前到达该节点

将循环条件更改为:

while (runner.Next != end)
这将确保在循环结束时,
runner
将恰好位于
end
节点之前

还请注意,此代码不处理
start
等于
end
的情况(当链接列表仅包含一个节点时)

while (runner.Next != end)