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

            if (this.tail == null)
            {
                return(default(T));
            }

            if (value.Equals(this.tail.GetValue()))
            {
                return(RemoveFromTail());
            }

            SinglyLinkedListElement <T> finger   = this.tail.GetNext();
            SinglyLinkedListElement <T> previous = null;

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

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

            if (previous == null)
            {
                return(RemoveFromHead());
            }
            else
            {
                previous.SetNext(finger.GetNext());
            }

            this.count--;
            return(finger.GetValue());
        }
예제 #2
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);
        }
예제 #3
0
 public void SetValue(T value)
 {
     Assertion.Pre(IsValid());
     this.cursor.SetValue(value);
 }
예제 #4
0
 public T GetValue()
 {
     Assertion.Pre(IsValid());
     return(this.cursor.GetValue());
 }
예제 #5
0
 public override T Next()
 {
     Assertion.Pre(HasMore());
     return(this.vector.GetElementAt(this.current++));
 }
예제 #6
0
 public override T PeekTail()
 {
     Assertion.Pre(this.tail != null);
     return(this.tail.GetValue());
 }