예제 #1
0
        public override T Remove(T value)
        {
            Assertion.Pre(value != null);

            SinglyLinkedListElement <T> finger   = this.head;
            SinglyLinkedListElement <T> previous = null;

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

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

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

            this.count--;

            return(finger.GetValue());
        }
예제 #2
0
        public override T RemoveFromTail()
        {
            Assertion.Pre(this.tail != null);

            SinglyLinkedListElement <T> finger  = this.tail;
            SinglyLinkedListElement <T> oldTail = this.tail;

            while (finger.GetNext() != this.tail)
            {
                finger = finger.GetNext();
            }

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

            this.count--;
            return(oldTail.GetValue());
        }
예제 #3
0
        public override T RemoveFromTail()
        {
            Assertion.Pre(this.head != null);

            SinglyLinkedListElement <T> previous = null;
            SinglyLinkedListElement <T> finger   = this.head;

            while (finger.GetNext() != null)
            {
                previous = finger;
                finger   = finger.GetNext();
            }

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

            this.count--;

            return(finger.GetValue());
        }
예제 #4
0
        public void TestSetGetNext()
        {
            Assert.AreEqual(null, element.GetNext());
            SinglyLinkedListElement <int> e = new SinglyLinkedListElement <int>(2, element);

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

            element.SetNext(e2);
            Assert.AreEqual(e2, element.GetNext());
        }
예제 #5
0
        public override T RemoveFromHead()
        {
            Assertion.Pre(this.head != null);

            SinglyLinkedListElement <T> oldHead = this.head;

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

            this.count--;

            return(oldHead.GetValue());
        }
예제 #6
0
        public override T PeekTail()
        {
            Assertion.Pre(this.head != null);

            SinglyLinkedListElement <T> finger = this.head;

            while (finger.GetNext() != null)
            {
                finger = finger.GetNext();
            }

            return(finger.GetValue());
        }
예제 #7
0
        public override bool Contains(T value)
        {
            Assertion.Pre(value != null);

            SinglyLinkedListElement <T> finger = this.head;

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

            return(finger != null);
        }
예제 #8
0
        public override void AddToHead(T value)
        {
            SinglyLinkedListElement <T> newHead = new SinglyLinkedListElement <T>(value);

            if (this.tail == null)
            {
                this.tail = newHead;
            }
            else
            {
                SinglyLinkedListElement <T> head = this.tail.GetNext();
                newHead.SetNext(head);
            }

            this.tail.SetNext(newHead);
            this.count++;
        }
예제 #9
0
        public override T RemoveFromHead()
        {
            Assertion.Pre(this.tail != null);

            SinglyLinkedListElement <T> head = this.tail.GetNext();

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

            this.count--;

            return(head.GetValue());
        }
예제 #10
0
        public override void AddToTail(T value)
        {
            SinglyLinkedListElement <T> newTail = new SinglyLinkedListElement <T>(value);

            if (this.head == null)
            {
                this.head = newTail;
            }
            else
            {
                SinglyLinkedListElement <T> finger = this.head;

                while (finger.GetNext() != null)
                {
                    finger = finger.GetNext();
                }

                finger.SetNext(newTail);
            }
            this.count++;
        }
예제 #11
0
        public override bool Contains(T value)
        {
            Assertion.Pre(value != null);

            SinglyLinkedListElement <T> finger = this.tail;

            if (finger == null)
            {
                return(false);
            }

            do
            {
                if (value.Equals(finger.GetValue()))
                {
                    return(true);
                }

                finger = finger.GetNext();
            } while (finger != this.tail);

            return(false);
        }
예제 #12
0
 public override void AddToTail(T value)
 {
     AddToHead(value);
     this.tail = this.tail.GetNext();
 }
예제 #13
0
 public void SetNext(SinglyLinkedListElement <T> next)
 {
     this.next = next;
 }
예제 #14
0
 public void TestSetup()
 {
     element = new SinglyLinkedListElement <int>(1);
 }
예제 #15
0
 public SinglyLinkedListElement(T value, SinglyLinkedListElement <T> next)
 {
     this.value = value;
     this.next  = next;
 }
예제 #16
0
 public override void AddToHead(T value)
 {
     this.head = new SinglyLinkedListElement <T>(value, this.head);
     this.count++;
 }
예제 #17
0
 public override void Clear()
 {
     this.head  = null;
     this.count = 0;
 }
예제 #18
0
 public override void Clear()
 {
     this.tail  = null;
     this.count = 0;
 }