// Java code to illustrate peek() function importjava.util.*; publicclassStackDemo{ publicstaticvoidmain(Stringargs[]) { // Creating an empty Stack Stack<String>STACK=newStack<String>(); // Use push() to add elements into the Stack STACK.push("Welcome"); STACK.push("To"); STACK.pus...
}returnthis.stackMin.peek(); }publicstaticvoidmain(String[] args) { MyStack1 stack1=newMyStack1(); stack1.push(3); System.out.println(stack1.getmin()); stack1.push(4); System.out.println(stack1.getmin()); stack1.push(1); System.out.println(stack1.getmin()); System.out.print...
java.util.stack类中常⽤的⼏个⽅法:isEmpty(),add(),remove(),contains()等各种⽅法都不难,但需要注意的是peek()这个⽅法。 peek()查看栈顶的对象⽽不移除它。import java.util.Stack;public class MyStack1 { private Stack<Integer> stackData;private Stack<Integer> stackMin;public My...