예제 #1
0
        /// <summary>
        /// 从链表里面获取一个随机节点的值
        /// </summary>
        /// <param name="index">自定义的链表开始索引</param>
        /// <param name="countOfElements">自定义的链表的结束索引</param>
        /// <returns>链表的节点值</returns>
        public SLinkedList <T> GetRange(int index, int countOfElements)
        {
            SLinkedList <T> newList     = new SLinkedList <T>();
            var             currentNode = this.m_FirstNode;

            // Handle Index out of Bound errors
            if (Count == 0)
            {
                return(newList);
            }
            else 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
 public void Dispose()
 {
     m_current          = null;
     m_doublyLinkedList = null;
 }
예제 #3
0
 public SLinkedListEnumerator(SLinkedList <T> list)
 {
     this.m_doublyLinkedList = list;
     this.m_current          = list.Head;
 }