Пример #1
0
 public bool MoveNext()
 {
     if (current == null || first == null)
     {
         current = first;
         return(current != null);
     }
     current = current.next;
     return(current != null);
 }
Пример #2
0
        public void Add(T item)
        {
            var newIt = new RestrictedQueueContainer <T>(item)
            {
                prev = null, next = null
            };

            if (length == 0 || maxQueueLength == 1)
            {
                first = newIt;
                last  = newIt;
                if (length < maxQueueLength)
                {
                    length++;
                }
                return;
            }

            if (length == 1)
            {
                first.next = newIt;
                newIt.prev = first;
                last       = newIt;
                length++;
                return;
            }

            if (length == maxQueueLength)
            {
                first.next.prev = null;
                first           = first.next;
            }
            else
            {
                length++;
            }

            last.next  = newIt;
            newIt.prev = last;
            last       = newIt;
        }
Пример #3
0
        public T DequeueLast()
        {
            if (last == null)
            {
                return(default(T));
            }
            if (length == 1)
            {
                var item = last.item;
                last    = null;
                first   = null;
                current = null;
                length  = 0;
                return(item);
            }

            var lastValue = last.item;
            var prevLast  = last.prev;

            prevLast.next = null;
            last          = prevLast;
            length--;
            return(lastValue);
        }
Пример #4
0
 public void Clear()
 {
     length = 0;
     first  = null;
     last   = null;
 }
Пример #5
0
 public void Reset()
 {
     current = null;
 }
Пример #6
0
 public void Dispose()
 {
     length = 0;
     first  = null;
     last   = null;
 }