Beispiel #1
0
        public void AddRangeFirst(IList <T> list)
        {
            if (list != null)
            {
                DoubleLinkedList <T> doubleList = DoubleLinkedList <T> .Create(list.ToArray());

                if (Length == 0)
                {
                    _root  = doubleList._root;
                    _tail  = doubleList._tail;
                    Length = doubleList.Length;
                }
                else if (doubleList.Length != 0)
                {
                    _root.Previous        = doubleList._tail;
                    doubleList._tail.Next = _root;
                    _root   = doubleList._root;
                    Length += doubleList.Length;
                }
            }
            else
            {
                throw new NullReferenceException("List is null");
            }
        }
Beispiel #2
0
        public void AddRangeByIndex(int index, IList <T> list)
        {
            if (list != null)
            {
                DoubleLinkedList <T> doubleList = DoubleLinkedList <T> .Create(list.ToArray());

                if (index >= 0 && index <= Length)
                {
                    if (index == 0)
                    {
                        AddRangeFirst(list);
                    }
                    else if (index == Length)
                    {
                        AddRange(list);
                    }
                    else
                    {
                        DoubleLinkedListNode <T> currentNode = GetNodeByIndex(index - 1);
                        doubleList._root.Previous = currentNode;
                        currentNode.Next.Previous = doubleList._tail;
                        doubleList._tail.Next     = currentNode.Next;
                        currentNode.Next          = doubleList._root;
                        Length += doubleList.Length;
                    }
                }
                else
                {
                    throw new IndexOutOfRangeException();
                }
            }
            else
            {
                throw new NullReferenceException("List is null");
            }
        }