public T PopAt(int index) { if (index == 0) { return(Pop()); } SetOfStacks <T> cursor = _previous; while (index-- > 0) { if (cursor._previous == null) { throw new ArgumentOutOfRangeException(); } cursor = cursor._previous; } return(cursor.Pop()); }
public T Pop() { while (_count == 0) { if (_previous == null) { throw new ArgumentOutOfRangeException(); } _count = _previous._count; _head = _previous._head; _previous = _previous._previous; } var value = _head.Value; _head = _head.Next; _count--; return(value); }
public void Push(T value) { if (_count >= _capacity) { _previous = new SetOfStacks <T>(this); _count = 0; _head = null; } var node = new Node(value); if (_head == null) { _head = node; } else { node.Next = _head; _head = node; } _count++; }