Пример #1
0
        public void SetNext(DoublyLinkedListElement <T> next)
        {
            this.next = next;

            if (next != null)
            {
                next.previous = this;
            }
        }
Пример #2
0
        public override void AddToHead(T value)
        {
            this.head = new DoublyLinkedListElement <T>(value, null, this.head);

            if (this.tail == null)
            {
                this.tail = this.head;
            }
        }
Пример #3
0
        public void SetPrevious(DoublyLinkedListElement <T> previous)
        {
            this.previous = previous;

            if (previous != null)
            {
                previous.next = this;
            }
        }
Пример #4
0
        public override void AddToTail(T value)
        {
            this.tail = new DoublyLinkedListElement <T>(value, this.tail, null);

            if (this.head == null)
            {
                this.head = this.tail;
            }
        }
Пример #5
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);
        }
Пример #6
0
        public void TestSetGetNext()
        {
            Assert.AreEqual(null, element.GetNext());
            DoublyLinkedListElement <int> e = new DoublyLinkedListElement <int>(2, null, element);

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

            element.SetNext(e2);
            Assert.AreEqual(e2, element.GetNext());
            Assert.AreEqual(element, e2.GetPrevious());
        }
Пример #7
0
        public DoublyLinkedListElement(T value, DoublyLinkedListElement <T> previous, DoublyLinkedListElement <T> next)
        {
            this.value    = value;
            this.previous = previous;

            if (previous != null)
            {
                previous.next = this;
            }

            this.next = next;

            if (next != null)
            {
                next.previous = this;
            }
        }
Пример #8
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());
        }
Пример #9
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());
        }
Пример #10
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());
        }
Пример #11
0
 public override void Clear()
 {
     this.head = null;
     this.tail = null;
 }
Пример #12
0
 public void TestSetup()
 {
     element = new DoublyLinkedListElement <int>(1);
 }