Example #1
0
        /// <summary>
        /// Inserts a specified item dataItem at an index.
        /// </summary>
        /// <param name="dataItem">Data item.</param>
        /// <param name="index">Index.</param>
        public void InsertAt(T dataItem, int index)
        {
            // Handle scope of insertion.
            // Prepend? Append? Or Insert in the range?
            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;

                // Increment the count
                _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
        /// <summary>
        /// Inserts the specified dataItem at the end of the list.
        /// </summary>
        /// <param name="dataItem">The data value to be inserted to the list.</param>
        public void Append(T dataItem)
        {
            SLinkedListNode <T> newNode = new SLinkedListNode <T>(dataItem);

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

            // Increment the count.
            _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(this._current != null);
            }
Example #7
0
 public SLinkedListEnumerator(SLinkedList <T> list)
 {
     this._doublyLinkedList = list;
     this._current          = list.Head;
 }