手记

字符反序输出用栈实现

class Reverser {
    private String input;
    private String output;
    public Reverser(String in)
    {
        input = in;
    }
    public String doRev() {
        StackX stackX = new StackX(input.length());
        char[] chs = input.toCharArray();
        for (int i = 0; i < chs.length; ++i)
            if (!stackX.isFull())
                stackX.push(chs[i]);
        output = "";
        while (!stackX.isEmpty())
            output += stackX.pop();
        return output;
    }
}
0人推荐
随时随地看视频
慕课网APP