我试图移动列表中的项目,但是当我比较最后一个选项时,我退出之前移动移动链接列表中的项目。有没有办法做到这一点,节点被放在最后,并不能循环移动项目?在链接列表中移动项目C#.NET
LinkedList<BD> list = new LinkedList<BD>(b[arg].Values);
LinkedListNode<BD> node, terminator, next = null;
List<LinkedListNode<BD>> move = new List<LinkedListNode<BD>>();
terminator = list.First;
node = next = list.Last;
while (next != null && next != terminator)
{
node = next;
next = next.Previous;
if (IDs.Contains(node.Value.Id))
{
move.Add(node);
list.Remove(node);
}
else
{
foreach (var item in move)
{
list.AddBefore(node, item);
node = node.Previous;
}
move.Clear();
}
}
请编辑您的问题,选择的代码部分,然后按小编辑器上方的“编码”按钮。这使得代码更易于阅读。 – Zyphrax 2009-07-29 21:51:04
@Zyphrax:为他们做到了。 – 2009-07-29 21:51:24
@ Bruce227:你能否描述一下你想要完成的事情?你是否想要分析节点,检查节点的DocumentVersionId是否在ID列表中,然后将该节点移动到链表的最前端? – Zyphrax 2009-07-29 22:05:56