Exemplo n.º 1
0
        public void TestSetGetPrevious()
        {
            Assert.AreEqual(null, element.GetPrevious());
            DoublyLinkedListElement <int> e = new DoublyLinkedListElement <int>(2, element, null);

            Assert.AreEqual(element, e.GetPrevious());
            Assert.AreEqual(e, element.GetNext());
            DoublyLinkedListElement <int> e2 = new DoublyLinkedListElement <int>(3);

            element.SetPrevious(e2);
            Assert.AreEqual(e2, element.GetPrevious());
            Assert.AreEqual(element, e2.GetNext());
        }
Exemplo n.º 2
0
        public override bool Contains(T value)
        {
            Assertion.Pre(value != null);

            DoublyLinkedListElement <T> finger = this.head;

            while (finger != null && !value.Equals(finger.GetValue()))
            {
                finger = finger.GetNext();
            }

            return(finger != null);
        }
Exemplo n.º 3
0
        public override T Remove(T value)
        {
            Assertion.Pre(value != null);

            DoublyLinkedListElement <T> finger = this.head;

            while (finger != null && !value.Equals(finger.GetValue()))
            {
                finger = finger.GetNext();
            }

            if (finger == null)
            {
                return(default(T));
            }

            if (finger.GetPrevious() != null)
            {
                finger.GetPrevious().SetNext(finger.GetNext());
            }
            else
            {
                this.head = finger.GetNext();
            }

            if (finger.GetNext() != null)
            {
                finger.GetNext().SetPrevious(finger.GetPrevious());
            }
            else
            {
                this.tail = finger.GetPrevious();
            }

            return(finger.GetValue());
        }