예제 #1
0
        /// <summary>
        /// Returns a number of elements as specified by countOfElements, starting from the specified index.
        /// </summary>
        /// <param name="index">Starting index.</param>
        /// <param name="countOfElements">The number of elements to return.</param>
        /// <returns>Singly-Linked List of elements</returns>
        public SLinkedList <T> GetRange(int index, int countOfElements)
        {
            SLinkedList <T> newList     = new SLinkedList <T>();
            var             currentNode = this._firstNode;

            // Handle Index out of Bound errors
            if (Count == 0)
            {
                return(newList);
            }

            if (index < 0 || index > Count)
            {
                throw new IndexOutOfRangeException();
            }

            // Move the currentNode reference to the specified index
            for (int i = 0; i < index; ++i)
            {
                currentNode = currentNode.Next;
            }

            // Append the elements to the new list using the currentNode reference
            while (currentNode != null && newList.Count <= countOfElements)
            {
                newList.Append(currentNode.Data);
                currentNode = currentNode.Next;
            }

            return(newList);
        }
예제 #2
0
        static void Main0(string[] args)
        {
            SLinkedList <string> list = new SLinkedList <string>();

            list.Append("HelloWorld!");
            Console.WriteLine(list.ToReadable());
            Console.WriteLine(list.Count);
        }
예제 #3
0
 public void Dispose()
 {
     _current          = null;
     _doublyLinkedList = null;
 }
예제 #4
0
 public SLinkedListEnumerator(SLinkedList <T> list)
 {
     this._doublyLinkedList = list;
     this._current          = list.Head;
 }