public int leftShift(int index, Boolean removeTop) { if (index <= list.Count - 1) { StackWithBottom <int> stack = list[index]; int toReturn; if (removeTop) { toReturn = stack.pop(); } else { toReturn = stack.removeBottom(); } if (stack.isEmpty()) { list.RemoveAt(index); } else if (index < list.Count - 1) { int item = leftShift(index + 1, false); stack.push(item); } return(toReturn); } else { throw new IndexOutOfRangeException(); } }
public int peek() { StackWithBottom <int> stack = getLastStack(); if (stack != null) { return(stack.peek()); } else { throw new NullReferenceException(); } }
public void push(int item) { StackWithBottom <int> lastStack = getLastStack(); if (lastStack != null && !lastStack.isFull()) { lastStack.push(item); } else { StackWithBottom <int> stack = new StackWithBottom <int>(capacity); stack.push(item); list.Add(stack); } }