Esempio n. 1
0
 private void AssertDifferentList(CircularLinkedList <T> list)
 {
     if (list == null)
     {
         throw new ArgumentNullException("List cannot be null");
     }
     if (list == this)
     {
         throw new InvalidOperationException("Cannot insert list into itself");
     }
 }
Esempio n. 2
0
        public void InsertAfter(Node node, CircularLinkedList <T> list)
        {
            AssertNodeNonNull(node);
            AssertDifferentList(list);

            Node next = node.Next;

            list.Tail.Next     = next;
            next.Previous      = list.Tail;
            list.Head.Previous = node;
            node.Next          = list.Head;

            if (node == Tail)
            {
                Tail = list.Tail;
            }

            Count += list.Count;
        }
Esempio n. 3
0
        public void InsertBefore(Node node, CircularLinkedList <T> list)
        {
            AssertNodeNonNull(node);
            AssertDifferentList(list);

            Node previous = node.Previous;

            list.Tail.Next     = node;
            node.Previous      = list.Tail;
            list.Head.Previous = previous;
            previous.Next      = list.Head;

            if (node == Head)
            {
                Head = list.Head;
            }

            Count += list.Count;
        }