Ejemplo n.º 1
0
        public void AddTail(T value)
        {
            var newNode = new CoolNode(value);

            if (this.Count == 0)
            {
                this._head = this._tail = newNode;
            }
            else
            {
                var oldTail = this._tail;
                oldTail.Next     = newNode;
                newNode.Previous = oldTail;
                this._tail       = newNode;
            }

            this.Count++;
        }
Ejemplo n.º 2
0
        public void AddHead(T value)
        {
            var newNode = new CoolNode(value);

            if (this.Count == 0)
            {
                this._head = this._tail = newNode;
            }
            else
            {
                var oldHead = this._head;
                oldHead.Previous = newNode;
                newNode.Next     = oldHead;
                this._head       = newNode;
            }

            this.Count++;
        }
Ejemplo n.º 3
0
        public T RemoveHead()
        {
            this.ValidateIfListIsEmpty();
            var value = this._head.Value;

            if (this._head == this._tail)
            {
                this._head = null;
                this._tail = null;
            }
            else
            {
                var newHead = this._head.Next;
                newHead.Previous = null;
                this._head.Next  = null;
                this._head       = newHead;
            }
            this.Count--;
            return(value);
        }
Ejemplo n.º 4
0
        public void Remove(T value)
        {
            var currentNode = this._head;

            while (currentNode != null)
            {
                var nodeValue = currentNode.Value;

                if (nodeValue.Equals(value))
                {
                    this.Count--;
                    var prevNode = currentNode.Previous;
                    var nextNode = currentNode.Next;
                    if (prevNode != null)
                    {
                        prevNode.Next = nextNode;
                    }

                    if (nextNode != null)
                    {
                        nextNode.Previous = prevNode;
                    }

                    if (this._head == currentNode)
                    {
                        this._head = nextNode;
                    }

                    if (this._tail == currentNode)
                    {
                        this._tail = prevNode;
                    }
                }
                currentNode = currentNode.Next;
            }
        }
Ejemplo n.º 5
0
 public void Clear()
 {
     this._head = null;
     this._tail = null;
     this.Count = 0;
 }