获取栈中任意位置的元素

public int getElement(Stack stack, int position)
    {
        int result = stack.pop();
        if (stack.size() == position)
        {
//            stack.push(result);
            return result;
        }else {
            int element = getElement(stack, position);
            stack.push(element);
            return element;
        }
    }

你可能感兴趣的:(python,算法)