Ejemplo n.º 1
0
        public void Remove(object value)
        {
            var current = this.head;

            while (current != null)
            {
                if (current.Value.Equals(value))
                {
                    this.Count--;
                    var prev = current.Prev;
                    var next = current.Next;
                    if (current != this.head)
                    {
                        prev.Next = next;
                    }
                    else
                    {
                        this.head = next;
                    }
                    if (current != this.tail)
                    {
                        next.Prev = prev;
                    }
                    else
                    {
                        this.tail = prev;
                    }
                }
                current = current.Next;
            }
        }
Ejemplo n.º 2
0
        public void AddTail(object value)
        {
            var newNode = new CoolNode(value);

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

            this.Count++;
        }
Ejemplo n.º 3
0
        public void AddHead(object 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.º 4
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.º 5
0
        public object RemoveTail()
        {
            ValidateIfIsEmpty();

            var oldTail = this.tail;

            if (this.head == this.tail)
            {
                this.head = null;
                this.tail = null;
            }
            else
            {
                var newTail = oldTail.Prev;
                this.tail      = newTail;
                this.tail.Next = null;
            }

            this.Count--;
            return(oldTail.Value);
        }
Ejemplo n.º 6
0
        public object RemoveHead()
        {
            ValidateIfIsEmpty();

            var oldHead = this.head;

            if (this.head == this.tail)
            {
                this.head = null;
                this.tail = null;
            }
            else
            {
                var newHead = this.head.Next;
                this.head      = newHead;
                this.head.Prev = null;
            }

            this.Count--;
            return(oldHead.Value);
        }
Ejemplo n.º 7
0
        public void Remove(object 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.º 8
0
        public object RemoveTail()
        {
            this.ValidateIfListIsEmpty();

            var value = this.tail.Value;

            if (this.head == this.tail)
            {
                this.head = null;
                this.tail = null;
            }
            else
            {
                var oldTail = this.tail;
                var newTail = this.tail.Previous;
                this.tail.Previous = null;
                this.tail          = newTail;
            }

            this.Count--;
            return(value);
        }
Ejemplo n.º 9
0
 public void Clear()
 {
     this.head  = null;
     this.tail  = null;
     this.Count = 0;
 }