Example #1
0
        public void InsertAt(T dataItem, int index)
        {
            if (index == 0)
            {
                Prepend(dataItem);
            }
            else if (index == Count)
            {
                Append(dataItem);
            }
            else if (index > 0 && index < Count)
            {
                var currentNode = _firstNode;
                var newNode     = new SLinkedListNode <T>(dataItem);

                for (int i = 1; i != index; ++i)
                {
                    currentNode = currentNode.Next;
                }

                newNode.Next     = currentNode.Next;
                currentNode.Next = newNode;

                _count++;
            }
            else
            {
                throw new IndexOutOfRangeException();
            }
        }
Example #2
0
        public int CompareTo(SLinkedListNode <T> other)
        {
            if (other == null)
            {
                return(-1);
            }

            return(this.Data.CompareTo(other.Data));
        }
Example #3
0
        public void Append(T dataItem)
        {
            var newNode = new SLinkedListNode <T>(dataItem);

            if (_lastNode == null)
            {
                _firstNode = newNode;
                _lastNode  = newNode;
            }
            else
            {
                _lastNode.Next = newNode;
                _lastNode      = newNode;
            }

            _count++;
        }
Example #4
0
 public void Dispose()
 {
     _current          = null;
     _doublyLinkedList = null;
 }
Example #5
0
 public void Reset()
 {
     _current = _doublyLinkedList.Head;
 }
Example #6
0
            public bool MoveNext()
            {
                _current = _current.Next;

                return(_current != null);
            }
Example #7
0
 public SLinkedListEnumerator(SLinkedList <T> list)
 {
     _doublyLinkedList = list;
     _current          = list.Head;
 }