Exemple #1
0
 public bool AddToEnd(T value)
 {
     if (First != null)
     {
         var newNode = new MyDoublyLinkedListNode <T>(value, First, Last);
         Last.Next        = newNode;
         First.Previous   = newNode;
         newNode.Next     = First;
         newNode.Previous = Last;
         Last             = newNode;
         return(true);
     }
     if (First == null)
     {
         var newNode = new MyDoublyLinkedListNode <T>(value);
         Last  = newNode;
         First = newNode;
         return(true);
     }
     return(false);
 }
Exemple #2
0
        public T RemoveEachGetLast(int eachN)
        {
            int num          = 1;
            var nodeToRemove = First;

            while (true)
            {
                if (num != eachN)
                {
                    nodeToRemove = nodeToRemove.Next;
                    num++;
                }
                else
                {
                    if (nodeToRemove == First)
                    {
                        First = nodeToRemove.Next;
                    }
                    if (nodeToRemove == Last)
                    {
                        Last = nodeToRemove.Previous;
                    }
                    var tempNode = nodeToRemove.Next;
                    nodeToRemove.RemoveNodeFromList();
                    nodeToRemove = tempNode;

                    if (nodeToRemove.Next == nodeToRemove)
                    {
                        break;
                    }
                    ShowList();
                    num = 1;
                }
            }
            return(nodeToRemove.Value);
        }
Exemple #3
0
 public MyDoublyLinkedListNode(T value, MyDoublyLinkedListNode <T> next, MyDoublyLinkedListNode <T> previous)
 {
     Value    = value;
     Next     = next;
     Previous = previous;
 }