/// <summary> /// Adds the value to the list, maintaining order. /// </summary> /// <remarks> /// This is an O(n) operation in the worst-case scenario. /// </remarks> /// <param name="value">The value to be added to the list.</param> public void Add(T value) { DoubleLinkedNode <T> newNode = CreateNode(value); DoubleLinkedNode <T> node = mInnerList; while (node != null && value.CompareTo(node.Value) < 1) { node = (DoubleLinkedNode <T>)node.Next; } if (node == null) { mInnerList = newNode; } else { node.Previous.Next = newNode; node.Previous = newNode; newNode.Next = node; } mCount++; }
/// <summary> /// Hook method that creates the details of the node that represents the /// supplied <paramref name="value"/>. /// </summary> /// <param name="value">The value to be stored in the queue.</param> /// <returns>The node for the queue.</returns> protected virtual DoubleLinkedNode <T> CreateNode(T value) { return(DoubleLinkedNode <T> .Instance(value, null, null)); }
/// <summary> /// Returns an instance of the node with the supplied <paramref name="value"/> and a pointer to the <paramref name="previous"/> /// and <paramref name="next"/> nodes in the list. /// </summary> /// <param name="value">The value of the node.</param> /// <param name="next">A pointer to the next node in the list.</param> /// <param name="previous">A pointer to the previous node in the list.</param> /// <returns>An instance of the node.</returns> public static DoubleLinkedNode <T> Instance(T value, DoubleLinkedNode <T> next, DoubleLinkedNode <T> previous) { return(new DoubleLinkedNode <T>(value, next, previous)); }
/// <summary> /// Constructor specifying the next and previous node in the list. /// </summary> /// <param name="value">Value being represented by this node.</param> /// <param name="next">The next node in the list.</param> /// <param name="previous">The previous node in the list.</param> protected DoubleLinkedNode(T value, DoubleLinkedNode <T> next, DoubleLinkedNode <T> previous) : base(value, next) { Previous = previous; }
/// <summary> /// Constructor specifying the next node in the list. /// </summary> /// <param name="value">Value being represented by this node.</param> /// <param name="next">The next node in the list.</param> protected DoubleLinkedNode(T value, DoubleLinkedNode <T> next) : this(value, next, null) { }
/// <summary> /// Removes all references to other <c>DoubleLinkedNode</c> instances to aid garbage collection. /// </summary> public override void Dispose() { Previous = null; base.Dispose(); }