Ejemplo n.º 1
0
        public void SetNext(DoublyLinkedListElement <T> next)
        {
            this.next = next;

            if (next != null)
            {
                next.previous = this;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 3
0
        public void SetPrevious(DoublyLinkedListElement <T> previous)
        {
            this.previous = previous;

            if (previous != null)
            {
                previous.next = this;
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 11
0
 public override void Clear()
 {
     this.head = null;
     this.tail = null;
 }
Ejemplo n.º 12
0
 public void TestSetup()
 {
     element = new DoublyLinkedListElement <int>(1);
 }