Пример #1
0
        public static void InsertAtEnd(DoubleNode <T> node, DoubleNode <T> insert)
        {
            var current = Last(node);

            insert.Previous = current;
            if (insert.Previous != null)
            {
                insert.Previous.Next = insert;
            }
        }
Пример #2
0
        public static void InsertAtBeginning(DoubleNode <T> node, DoubleNode <T> insert)
        {
            var current = First(node);

            insert.Next = current;
            if (current != null)
            {
                current.Previous = insert;
            }
        }
Пример #3
0
        public static DoubleNode <T> Last(DoubleNode <T> node)
        {
            var current = node;

            while (current != null && current.Next != null)
            {
                current = current.Next;
            }
            return(current);
        }
Пример #4
0
        public static DoubleNode <T> First(DoubleNode <T> node)
        {
            var current = node;

            while (current != null && current.Previous != null)
            {
                current = current.Previous;
            }
            return(current);
        }
Пример #5
0
 public static void InsertBefore(DoubleNode <T> node, DoubleNode <T> insert)
 {
     insert.Next = node;
     if (node != null && node.Previous != null)
     {
         node.Previous.Next = insert;
     }
     if (node != null)
     {
         node.Previous = insert;
     }
 }
Пример #6
0
 public static void InsertAfter(DoubleNode <T> node, DoubleNode <T> insert)
 {
     insert.Previous = node;
     insert.Next     = node.Next;
     if (node != null && node.Next != null)
     {
         node.Next.Previous = insert;
     }
     if (node != null)
     {
         node.Next = insert;
     }
 }
Пример #7
0
        public static void RemoveNode(DoubleNode <T> node, DoubleNode <T> remove)
        {
            var current = First(node);

            while (current.Next != null)
            {
                if (current == remove)
                {
                    var previous = current.Previous;
                    var next     = current.Next;
                    previous.Next = next;
                    next.Previous = previous;
                }
                current = current.Next;
            }
        }