Ejemplo n.º 1
0
 public bool Remove(DualLinkedNode <T> node, out T value)
 {
     value = default;
     if (node == null)
     {
         return(false);
     }
     value = node.Content;
     if (First == null)
     {
         return(false);
     }
     if (node == First)
     {
         First = First.Next;
     }
     else
     {
         var previous = node.Previous;
         var next     = node.Next;
         if (next != null)
         {
             next.Previous = previous;
         }
         previous.Next = next;
     }
     return(true);
 }
Ejemplo n.º 2
0
        public void Add(DualLinkedNode <T> previous, T value)
        {
            var node = new DualLinkedNode <T>()
            {
                Content = value
            };

            //if the first node does not exist, it is filled
            if (First == null)
            {
                First = node;
                return;
            }

            if (previous == null)
            {
                //Changes the node's next pointer to the first node
                node.Next = First;
                //changes t
                First.Previous = node;
                First          = node;
            }
            else
            {
                var next = previous.Next;
                node.Previous = previous;
                node.Next     = next;
                previous.Next = node;
                if (next != null)
                {
                    next.Previous = node;
                }
            }
        }