コード例 #1
0
        /// <summary>
        /// Inserts a value at the specified index.
        /// </summary>
        public void InsertAt(T value, int index)
        {
            DoublyLinkedListNode <T> nodeToInsert;

            if (index == 0)
            {
                nodeToInsert      = new DoublyLinkedListNode <T>(value, index);
                nodeToInsert.Next = this.head;
                this.head         = nodeToInsert;
                this.Count++;
                this.NormalizeIndexes(this.head);
                return;
            }
            else
            {
                DoublyLinkedListNode <T> prevNode = this.FindNode(index).Previous;
                nodeToInsert          = new DoublyLinkedListNode <T>(value, index);
                nodeToInsert.Next     = prevNode.Next;
                nodeToInsert.Previous = prevNode;
                prevNode.Next         = nodeToInsert;
                this.Count++;
                this.NormalizeIndexes(prevNode);
            }
        }
コード例 #2
0
 public DoublyLinkedList(T value)
 {
     this.head       = new DoublyLinkedListNode <T>(value);
     this.head.Index = 0;
     this.Count++;
 }