Пример #1
0
            public int peek()
            {
                int        lastStackIndex = listOfStacks.Count - 1;
                StackPlate stack          = getStack(lastStackIndex);

                return(stack.peek());
            }
Пример #2
0
            public int pop()
            {
                int        lastStackIndex = listOfStacks.Count - 1;
                StackPlate stack          = getStack(lastStackIndex);
                int        val            = stack.pop();

                if (stack.isEmpty() && this.listOfStacks.Count > 1)
                {
                    listOfStacks.RemoveAt(lastStackIndex);
                }

                return(val);
            }
Пример #3
0
            public void push(int item)
            {
                StackPlate stack = getStack(listOfStacks.Count - 1);

                if (!stack.isFull())
                {
                    stack.push(item);
                }
                else
                {
                    stack = new StackPlate(this.capacityStacks);
                    stack.push(item);
                    listOfStacks.Add(stack);
                }
            }
Пример #4
0
            private int leftShif(int index)
            {
                int        numberStacks = listOfStacks.Count;
                StackPlate prevStack    = getStack(index);
                int        result       = prevStack.pop();

                for (int i = index + 1; i < numberStacks; i++)
                {
                    StackPlate stack = getStack(i);
                    int        val   = stack.getBottom();
                    if (stack.isEmpty() && this.listOfStacks.Count > 1)
                    {
                        listOfStacks.RemoveAt(i);
                    }
                    prevStack.push(val);
                    prevStack = stack;
                }
                return(result);
            }