public void Push(int item) { MyStack last = GetLastStack(); if (last != null && !last.IsFull()) { last.Push(item); } else { MyStack stack = new MyStack(capacity); stack.Push(item); stacks.Add(stack); } }
public int Pop() { MyStack last = GetLastStack(); if (last == null) { throw new NullReferenceException(); } int item = last.Pop(); if (last.size == 0) { stacks.Remove(stacks[stacks.Count - 1]); } return(item); }
public int LeftShift(int index, bool removeTop) { MyStack stack = stacks[index]; int removed_item; removed_item = (removeTop) ? stack.Pop() : stack.RemoveBottom(); if (stack.IsEmpty()) { stacks.Remove(stacks[index]); } else if (stacks.Count > index + 1) { int item = LeftShift(index + 1, false); stack.Push(item); } return(removed_item); }
public bool IsEmpty() { MyStack last = GetLastStack(); return(last == null || last.IsEmpty()); }