public DLinkedList <T> Duplicate() { var result = new DLinkedList <T>(); foreach (var v in this) { var n = new DLinkedListNode <T>(v); result.AddLast(n); } return(result); }
/// <summary> /// Make sublist from give index, and up to size /// </summary> /// <param name="index"></param> /// <param name="size">if -1 then up to end of list</param> /// <returns></returns> public DLinkedList <T> Duplicate(int index, int size) { Debug.Assert(index >= 0); var result = new DLinkedList <T>(); if (index >= Count) { return(result); } var current = GetNodeAtIndex(index); while (current != null && (size < 0 || size > 0)) { var n = new DLinkedListNode <T>(current.Value); result.AddLast(n); size--; current = current.Next; } return(result); }