Ejemplo n.º 1
0
 void Add(DoublyLinking <T> node, DoublyLinking <T> selected, bool isnEnd = true)
 {
     ++Length;
     if (selected == null)
     {
         head = current = end = node;
         return;
     }
     node.PreviousLinq = isnEnd ? selected?.PreviousLinq : selected;
     node.NextLinq     = isnEnd ? selected : null;
     if (isnEnd)
     {
         if (node.PreviousLinq != null)
         {
             selected.PreviousLinq.NextLinq = node;
             selected.PreviousLinq          = node;
         }
         else
         {
             selected.PreviousLinq = node;
             head = node;
         }
     }
     else
     {
         selected.NextLinq = node;
         end = node;
     }
 }
Ejemplo n.º 2
0
        public void DeleteCurrent()
        {
            if (current == null)
            {
                throw new DeleteNullExeption();
            }

            --Length;
            if (Length == 1)
            {
                end = head = current = null;
                return;
            }


            DoublyLinking <T> buffer = null;

            buffer = current == head ? current.NextLinq : current.PreviousLinq;
            if (current == head)
            {
                head = current.NextLinq;
            }
            else if (current == end)
            {
                end = current.PreviousLinq;
            }
            else
            {
                current.PreviousLinq.NextLinq = current.NextLinq;
                current.NextLinq.PreviousLinq = current.PreviousLinq;
            }
            current = buffer;
        }
Ejemplo n.º 3
0
        public void ChangeCurrent(int count = 1)
        {
            if (count == 0)
            {
                return;
            }
            int indexOfCurrentAfterChange = GetIndexOfCurrent() + count;

            if ((indexOfCurrentAfterChange < 0) || (indexOfCurrentAfterChange > Length - 1))
            {
                throw new MoveExeption();
            }
            DoublyLinking <T> GetNextLinq() => current.NextLinq;
            DoublyLinking <T> GetPreviousLinq() => current.PreviousLinq;

            Func <DoublyLinking <T> > getLinq = count > 0 ? (Func <DoublyLinking <T> >)GetNextLinq : GetPreviousLinq;

            for (var i = 0; i < Math.Abs(count); ++i)
            {
                current = getLinq();
            }
        }
Ejemplo n.º 4
0
 public void GoToEnd()
 {
     current = end;
 }
Ejemplo n.º 5
0
 public void GoToHead()
 {
     current = head;
 }
Ejemplo n.º 6
0
 internal DoublyLinking(T value)
 {
     PreviousLinq = null;
     Value        = value;
     NextLinq     = null;
 }