Advertisement

Java 压栈和弹栈的操作

阅读量:

字符串逆序栈实现方法

完整代码实现

复制代码
    import java.io.IOException;
     
    public class StringReverserThroughStack {
       private String input; 
       private String output;
       public StringReverserThroughStack(String in) {
      input = in;
       }
       public String doRev() {
      int stackSize = input.length(); 
      Stack theStack = new Stack(stackSize); 
      for (int i = 0; i < input.length(); i++) {
         char ch = input.charAt(i); 
         theStack.push(ch); 
      }
      output = "";
      while (!theStack.isEmpty()) {
         char ch = theStack.pop(); 
         ou

全部评论 (0)

还没有任何评论哟~