예제 #1
0
        /// <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++;
        }
예제 #2
0
 /// <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));
 }
예제 #3
0
 /// <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));
 }
예제 #4
0
 /// <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;
 }
예제 #5
0
 /// <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)
 {
 }
예제 #6
0
 /// <summary>
 /// Removes all references to other <c>DoubleLinkedNode</c> instances to aid garbage collection.
 /// </summary>
 public override void Dispose()
 {
     Previous = null;
     base.Dispose();
 }