我試圖移動列表中的項目,但是當我比較最後一個選項時,我退出之前移動移動鏈接列表中的項目。有沒有辦法做到這一點,節點被放在最後,並不能循環移動項目?在鏈接列表中移動項目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