Пример #1
0
        public override void Insert(T value)
        {
            base.size++;
            SONode <T> newNode = new SONode <T>(value);

            lastNode.SetNext(newNode);
            lastNode = newNode;
        }
Пример #2
0
 public bool MoveNext()
 {
     if (current != null)
     {
         current = current.Next;
     }
     return(current != null);
 }
Пример #3
0
        private T[] CreateTailArray(SONode <T> firstElement, int size)
        {
            T[] array = new T[size];

            for (int i = 0; i < size; i++)
            {
                array[i]     = firstElement.Value;
                firstElement = firstElement.Next;
            }

            return(array);
        }
Пример #4
0
        public override void Remove(T value)
        {
            SONode <T> current = base.preHead;

            while (current.Next != null)
            {
                if (EqualityComparer <T> .Default.Equals(current.Next.Value, value))
                {
                    current.SetNext(current.Next.Next);
                    current.Next.SetNext(null);
                    break;
                }
            }
        }
Пример #5
0
        public override T[] GetTail(T origin)
        {
            SONode <T> iter       = base.preHead.Next;
            int        startIndex = 0;

            while (iter != null)
            {
                if (EqualityComparer <T> .Default.Equals(origin, iter.Value))
                {
                    int arraySize = size - startIndex - 1;
                    T[] tail      = CreateTailArray(iter.Next, arraySize);

                    return(tail);
                }
                iter = iter.Next;
                startIndex++;
            }

            T[] empty = new T[0];
            return(empty);
        }
Пример #6
0
        public override bool Contains(T value)
        {
            SONode <T> prev = base.preHead;
            SONode <T> next = prev.Next;

            for (;
                 next != null;
                 next = next.Next)
            {
                if (EqualityComparer <T> .Default.Equals(next.Value, value))
                {
                    prev.SetNext(next.Next);
                    next.SetNext(preHead.Next);
                    preHead.SetNext(next);

                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
 public void Reset()
 {
     current = preHead;
 }
Пример #8
0
 public SOListIterator(SONode <T> head)
 {
     this.current = head;
     this.preHead = head;
 }
Пример #9
0
 protected SOListBase(SONode <T> preHead)
 {
     this.preHead = preHead;
     this.size    = 0;
 }
Пример #10
0
 public mtfSOList() : base(new SONode <T>())
 {
     lastNode = base.preHead;
 }