Ejemplo n.º 1
0
        public bool Remove(T item)
        {
            var current = _head;

            while (current != null)
            {
                if (current.Value.Equals(item))
                {
                    if (current.Previous == null)//head
                    {
                        _head = current.Next;
                        current.Next.Previous = null;
                        current = null;
                    }
                    else if (current.Next == null) //tail
                    {
                        _tail = current.Previous;
                        current.Previous.Next = null;
                    }
                    else
                    {
                        current.Previous.Next = current.Next;
                    }
                    _count -= 1;
                    return(true);
                }
                current = current.Next;
            }
            return(false);
        }
Ejemplo n.º 2
0
        public void AddLast(T item)
        {
            var node = new DLLNode <T>(item);

            if (_tail != null)
            {
                _tail.Next    = node;
                node.Previous = _tail;
                _tail         = node;
            }
            else
            {
                _head = node;
                _tail = node;
            }
            _count += 1;
        }
Ejemplo n.º 3
0
        public void AddFirst(T item)
        {
            var         node = new DLLNode <T>(item);
            DLLNode <T> temp = _head;

            _head = node;

            if (_count > 0)
            {
                temp.Previous = node;
                node.Next     = temp;
            }
            else
            {
                _head = node;
                _tail = node;
            }
            _count += 1;
        }
Ejemplo n.º 4
0
 public void Clear()
 {
     _count = 0;
     _head  = null;
     _tail  = null;
 }