示例#1
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);
        }
示例#2
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());
        }
示例#3
0
        public override T RemoveFromTail()
        {
            Assertion.Pre(this.tail != null);

            DoublyLinkedListElement <T> oldTail = this.tail;

            this.tail = this.tail.GetPrevious();

            if (this.tail == null)
            {
                this.head = null;
            }
            else
            {
                this.tail.SetNext(null);
            }

            return(oldTail.GetValue());
        }
示例#4
0
        public override T RemoveFromHead()
        {
            Assertion.Pre(this.head != null);

            DoublyLinkedListElement <T> oldHead = this.head;

            this.head = this.head.GetNext();

            if (this.head == null)
            {
                this.tail = null;
            }
            else
            {
                this.head.SetPrevious(null);
            }

            return(oldHead.GetValue());
        }
示例#5
0
 public void TestSetGetValue()
 {
     Assert.AreEqual(1, (int)element.GetValue());
     element.SetValue(2);
     Assert.AreEqual(2, (int)element.GetValue());
 }