/// <summary> /// Enqueue an item to the front, instead of to the back like the regular /// enqueue method /// </summary> /// <param name="value">The value to append to the front of the queue</param> public void EnqueueFront(T value) { if (IsFull()) { throw new InvalidOperationException("Cannot enqueue to full queue"); } else if (IsEmpty()) { Front = new DoubleListNode <T>(value); Front = End; Count++; } else { Front.Previous = new DoubleListNode <T>(value, null, Front); Front = Front.Previous; Count++; } }
/// <summary> /// Add an item to the beginning of this queue /// </summary> /// <param name="value">The value to add to the front of this queue</param> public void Enqueue(T value) { if (IsFull()) { throw new InvalidOperationException("Cannot enqueue to full queue"); } //Insert the first node, Else, Queue non-empty, non-full. New End is the next node if (IsEmpty()) { Front = new DoubleListNode <T>(value); End = Front; Count++; } else { End.Next = new DoubleListNode <T>(value, End, null); End = End.Next; Count++; } }
/// <summary> /// Constructs a doubly linked list node from a value and pointers to previous and next node /// </summary> /// <param name="value">Value held by this node</param> /// <param name="previous">Previous DoubleListNode in the sequence</param> /// <param name="next">Next DoubleListNode in the sequence</param> public DoubleListNode(T value, DoubleListNode <T> previous, DoubleListNode <T> next) : base(value, next) { Previous = previous; }