zoukankan      html  css  js  c++  java
  • 个人算法小题小结


    //两个栈实现队列功能
    public class TestALL {
    public Stack<Integer> firstStack;
    public Stack<Integer> secondStack;
    public TestALL(){
    firstStack=new Stack<Integer>();
    secondStack=new Stack<Integer>();

    }
    public void add(int scannerInt){
    firstStack.push(scannerInt);
    }
    public int poll(){
    if(firstStack.isEmpty()&&secondStack.isEmpty()){
    throw new RuntimeException("栈为空");
    }else if(secondStack.isEmpty()){
    while(!firstStack.isEmpty()){
    secondStack.push(firstStack.pop());
    }
    }
    return secondStack.pop();
    }
    public int peek(){
    if(firstStack.isEmpty()&&secondStack.isEmpty()){
    throw new RuntimeException("栈为空");
    }else if(secondStack.isEmpty()){
    while(!firstStack.isEmpty()){
    secondStack.push(firstStack.pop());
    }
    }
    return secondStack.peek();
    }
    }
  • 相关阅读:
    排序小结
    递推
    基准线
    毫无思绪
    计蒜客A
    尼克的任务
    售货员的难题
    Renting Boats
    工业物联网实践指南----专注生产制造活动
    阿里云单域名免费SSL证书安装
  • 原文地址:https://www.cnblogs.com/KingIceMou/p/7050021.html
Copyright © 2011-2022 走看看