Exemplo n.º 1
0
        public void Remove(T data)
        {
            if (Head != null)
            {
                if (Head.Data.Equals(data))
                {
                    Head = Head.Next;
                    Count--;
                }

                var current  = Head;
                var previous = Head;

                while (current.Next != null)
                {
                    if (current.Data.Equals(data))
                    {
                        previous.Next = current.Next;
                        Count--;
                    }
                    previous = current;
                    current  = current.Next;
                }
                AddToRemoveList?.Invoke(data);
            }
        }
Exemplo n.º 2
0
        public T Pop()
        {
            if (IsEmpty)
            {
                throw new InvalidOperationException("Stack is emplty");
            }
            Node <T> previous = head;

            head = head.Next;
            count--;
            AddToRemoveList?.Invoke(previous.Data);
            return(previous.Data);
        }