Пример #1
0
        public T Pop()
        {
            if (IsEmpty())
            {
                throw new Exception("Stack is empty, nothing to pop.");
            }

            var nextStackItem = _stackItem.NextItem;
            var valueToReturn = _stackItem.ObjectValue;

            _stackItem = nextStackItem;
            return(valueToReturn);
        }
 public MyStackItem(T value, MyStackItem <T> nextStackItem)
 {
     ObjectValue = value;
     NextItem    = nextStackItem;
 }
Пример #3
0
        public void Push(T data)
        {
            var stackItem = new MyStackItem <T>(data, _stackItem);

            _stackItem = stackItem;
        }