Ejemplo n.º 1
0
        public void remove(object e)
        {
            if (first == null)
            {
                return;
            }
            if (first.e.Equals(e))
            {
                first = first.next;
                SIZE--;
                return;
            }
            LinkedNode node = first;

            while (node != null)
            {
                if (node.Equals(e) && node.next != null)
                {
                    node.next = node.next.next;
                    SIZE--;
                    return;
                }
                node = node.next;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Removes the given value from the list.</para>
        /// <para>Expected Runtime: O(n), where n is the number of elements in the list.</para>
        /// </summary>
        /// <param name="value"></param>
        public void Remove(T value)
        {
            LinkedNode <T> currentNode  = this.headNodeOfList;
            LinkedNode <T> previousNode = currentNode;

            while (currentNode.Value.Equals(value) == false)
            {
                previousNode = currentNode;
                currentNode  = currentNode.Next;

                //Reached the end of the list, value wasn't in the lsit to begin with
                //Exit
                if (currentNode == null)
                {
                    return;
                }
            }

            //Handle cases
            if (currentNode.Equals(this.headNodeOfList))
            {
                this.headNodeOfList = this.headNodeOfList.Next;
            }
            else if (currentNode.Equals(this.tailNodeOfList))
            {
                this.tailNodeOfList      = previousNode;
                this.tailNodeOfList.Next = null;
            }
            else
            {
                previousNode.Next = currentNode.Next;
            }

            //Invalidate all of the caches
            this.isCachedCountValid = false;
            if (currentNode.Value.Equals(this.GetMinimum()))
            {
                this.isCachedMinimumValid = false;
            }
            if (currentNode.Value.Equals(this.GetMaximum()))
            {
                this.isCachedMaximumValid = false;
            }

            //Remove the node and its value
            currentNode.Remove();
        }