Пример #1
0
        public void RemoveTest()
        {
            Assert.IsTrue(threeList.Remove(3));
            Assert.AreEqual(2, threeList.Count);

            int[] values = { 2, 4 };
            int   i      = 0;

            foreach (int current in threeList)
            {
                Assert.AreEqual(values[i], current);
                i++;
            }
            Assert.IsFalse(threeList.Remove(5));

            CircularLinkedListNode <string> node = stringList.Find("baz");

            stringList.Remove(node);

            Assert.IsNull(node.List);
            Assert.IsNull(node.Previous);
            Assert.IsNull(node.Next);

            string[] values2 = { "foo", "bar" };
            i = 0;
            foreach (string current in stringList)
            {
                Assert.AreEqual(values2[i], current);
                i++;
            }
        }
Пример #2
0
        /// <summary>
        /// Removes nodes from the arguments list and inserts them at the end of the target list.
        /// </summary>
        /// <param name="srcFirst">The first node in the source list.</param>
        /// <param name="srcLast">The last node in the source list.</param>
        public void SpliceLast(CircularLinkedListNode <T> srcFirst, CircularLinkedListNode <T> srcLast)
        {
            if (srcFirst == null)
            {
                throw new ArgumentNullException("srcFirst");
            }
            if (srcLast == null)
            {
                throw new ArgumentNullException("srcLast");
            }
            if (srcFirst.List != srcLast.List)
            {
                throw new InvalidOperationException("source nodes not in same list");
            }
            CircularLinkedList <T>     srcList    = srcFirst.List;
            CircularLinkedListNode <T> terminator = srcLast.Next;
            CircularLinkedListNode <T> node       = srcFirst;

            do
            {
                CircularLinkedListNode <T> nextNode = node.Next;
                srcList.Remove(node);
                this.AddLast(node);
                node = nextNode;
            }while (node != terminator);
        }