Ejemplo n.º 1
0
        public void Prepend(int value)
        {
            var newNode = new DoubleNode(value);

            this.head.Previous = newNode;
            newNode.Next       = this.head;
            this.head          = newNode;
            this.length++;
        }
Ejemplo n.º 2
0
        public void Append(int value)
        {
            var newNode = new DoubleNode(value);

            newNode.Previous = this.tail;
            this.tail.Next   = newNode;
            this.tail        = newNode;
            this.length++;
        }
Ejemplo n.º 3
0
        public void Remove(int index)
        {
            if (index > this.length)
            {
                return; // let's just get out of here.
            }

            if (index == 0)
            {
                this.head          = this.head.Next;
                this.head.Previous = null;
                return; // let's just get out of here.
            }

            var removedNode = this.TraverseToIndex(index);

            removedNode.Previous.Next = removedNode.Next;
            removedNode.Next.Previous = removedNode.Previous;
            this.length--;
        }
Ejemplo n.º 4
0
        public void Insert(int index, int value)
        {
            if (this.length == 1)
            {
                this.Prepend(value);
                return;
            }

            if (index >= this.length)
            {
                this.Append(value);
                return;
            }

            var newNode = new DoubleNode(value);

            var leader = this.TraverseToIndex(index - 1);

            newNode.Previous = leader;
            newNode.Next     = leader.Next;
            leader.Next      = newNode;
            this.length++;
        }
Ejemplo n.º 5
0
 public DoubleNode(int value)
 {
     this.Value    = value;
     this.Next     = null;
     this.Previous = null;
 }
Ejemplo n.º 6
0
 public DoublyLinkedList(int value)
 {
     this.head = new DoubleNode(value);
     this.tail = this.head;
     this.length++;
 }