예제 #1
0
        public int Pop(WhichStack whichStack)
        {
            int value;

            if (IsEmpty(whichStack))
            {
                return(0);
            }
            switch (whichStack)
            {
            case WhichStack.One:
                value = _intArray[_arrayStartIndex[0] + _stackCount[0] - 1];
                _stackCount[0]--;
                return(value);

            case WhichStack.Two:
                value = _intArray[_arrayStartIndex[1] + _stackCount[1] - 1];
                _stackCount[1]--;
                return(value);

            case WhichStack.Three:
                value = _intArray[_arrayStartIndex[2] + _stackCount[2] - 1];
                _stackCount[2]--;
                return(value);

            default:
                return(0);
            }
        }
예제 #2
0
        public bool IsFull(WhichStack whichStack)
        {
            switch (whichStack)
            {
            case WhichStack.One: return(!(_stackCount[0] < (_intArray.Length / 3)));

            case WhichStack.Two: return(!(_stackCount[1] < (_intArray.Length / 3)));

            case WhichStack.Three: return(!(_stackCount[2] < (_intArray.Length / 3)));

            default: return(false);
            }
        }
예제 #3
0
        public bool IsEmpty(WhichStack whichStack)
        {
            switch (whichStack)
            {
            case WhichStack.One:
                return(_stackCount[0] == 0);

            case WhichStack.Two:
                return(_stackCount[1] == 0);

            case WhichStack.Three:
                return(_stackCount[2] == 0);

            default: return(false);
            }
        }
예제 #4
0
        public int Peek(WhichStack whichStack)
        {
            if (IsEmpty(whichStack))
            {
                return(0);
            }
            switch (whichStack)
            {
            case WhichStack.One: return(_intArray[_arrayStartIndex[0] + _stackCount[0]]);

            case WhichStack.Two: return(_intArray[_arrayStartIndex[1] + _stackCount[1]]);

            case WhichStack.Three: return(_intArray[_arrayStartIndex[2] + _stackCount[2]]);

            default: return(0);
            }
        }
예제 #5
0
        public void Push(int value, WhichStack whichStack)
        {
            if (IsFull(whichStack))
            {
                throw new Exception("Stack is Full");
            }
            switch (whichStack)
            {
            case WhichStack.One:
                _intArray[(_arrayStartIndex[0] + _stackCount[0])] = value;
                _stackCount[0]++;
                break;

            case WhichStack.Two:
                _intArray[(_arrayStartIndex[1] + _stackCount[1])] = value;
                _stackCount[1]++;
                break;

            case WhichStack.Three:
                _intArray[(_arrayStartIndex[2] + _stackCount[2])] = value;
                _stackCount[2]++;
                break;
            }
        }