public int Pop() { Stack1 last = Stacks[Stacks.Count - 1]; int value = last.Pop(); if (last.size == 0) //need to check if stack is empty now -- so need a size attribute in the custom stack class { //since the last stack is empty .. remove it. Stacks.RemoveAt(Stacks.Count - 1); } return(value); }
public void Push(int value) { Stack1 last = Stacks[Stacks.Count - 1]; if (last != null && !last.IsAtCapacity()) { //add to last stack last.Push(value); } else { //create new stack Stack1 s1 = new Stack1(capacity); //need capacity of the new stack at creation time, so passed it in SetOfStacks ctor s1.Push(value); //add new stack to list of stacks Stacks.Add(s1); } }