Пример #1
0
 public HeadTailList(T head)
 {
     _hasHead = true;
     _head    = head;
     _tail    = null;
     Count    = 1;
 }
Пример #2
0
 public HeadTailList(T head, HeadTailList <T> tail)
 {
     _hasHead = true;
     _head    = head;
     _tail    =
         tail == null || tail.IsEmpty
         ? null
         : tail;
     Count = 1 + (tail?.Count ?? 0);
 }
Пример #3
0
        private static T[] ToArray(HeadTailList <T> list, T[] array, int currentIndex)
        {
            if (!list._hasHead)
            {
                return(array);
            }

            array[currentIndex] = list._head;

            if (!(list._tail?._hasHead ?? false))
            {
                return(array);
            }

            return(ToArray(list._tail, array, currentIndex + 1));
        }
Пример #4
0
        private static T GetItem(HeadTailList <T> list, int currentIndex, int index)
        {
            var head =
                list._hasHead
                ? list._head
                : throw new ArgumentOutOfRangeException(nameof(index), index, "Argument is out of range.");

            if (currentIndex == index)
            {
                return(head);
            }

            var tail =
                list._tail?._hasHead ?? false
                ? list._tail
                : throw new ArgumentOutOfRangeException(nameof(index), index, "Argument is out of range.");

            return(GetItem(list._tail, currentIndex + 1, index));
        }
Пример #5
0
 public void Deconstruct(out T head, out HeadTailList <T> tail)
 {
     head = Head;
     tail = Tail;
 }
Пример #6
0
 public HeadTailListEnumerator(HeadTailList <T> list)
 {
     _original = list;
     _current  = null;
 }