zoukankan      html  css  js  c++  java
  • Stack

    import java.util.Stack;
    
    public class StackTest {
    	public static void main(String[] args) {
    		Stack<String> stack = new Stack<String>();
    		System.out.println("now the stack is " + isEmpty(stack));
    		stack.push("1");
    		stack.push("2");
    		stack.push("3");
    		stack.push("4");
    		stack.push("5");
    		System.out.println("now the stack is " + isEmpty(stack));
    		System.out.println(stack.peek());
    		System.out.println(stack.pop());
    		System.out.println(stack.pop());
    		System.out.println(stack.search("2"));
    	}
    	
    	public static String isEmpty(Stack<String> stack) {
    		return stack.empty() ? "empty" : "not empty";
    	}
    }
    

      

    now the stack is empty
    now the stack is not empty
    5
    5
    4
    2

    search(Object o)

    Returns the 1-based position where an object is on this stack.
  • 相关阅读:
    题解-CF468E Permanent
    CSP2021 游记
    二项式系数相关
    欧拉反演
    欧拉函数
    [快速幂]1
    GMT绘制地形起伏
    华为mate8双击唤醒屏幕
    回家乡了
    CSP-S2021
  • 原文地址:https://www.cnblogs.com/lnas01/p/4534346.html
Copyright © 2011-2022 走看看