9. 13. 6. Stack基本用法 To find out if an element is on the stack: the search() method
2011-09-29 21:10
561 查看
import java.util.Stack; public class StackLastinFirstout { public static void main(String[] args) { Stack s = new Stack(); s.push("A"); s.push("B"); s.push("C"); System.out.println(s); System.out.println(s.pop());//移除堆栈顶部的对象,并作为此函数的值返回该对象-最后一项 C System.out.println("Next: " + s.peek());//查看堆栈顶部的对象,但不从堆栈中移除它。最后一项 C s.push("E"); int count = s.search("E");//返回对象在堆栈中的位置,以 1 为基数。 while(count!=-1&&count>1){ s.pop(); count--; } System.out.println(s); } }
相关文章推荐
- rsync - find - perl - Which is the fastest method to delete files in Linux
- Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath.Perhaps JAVA_HOME does not point to the JDK
- Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath.Perhaps JAVA_HOME
- The way to select how large is diesel-engined keep an eye on
- [ios] how to findout the language you use on ios devices.
- Python 出现错误 SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform.
- [转]How to remove an assembly from the Cache if it is locked by Microsoft Installer
- Give an O(log m + log n) algorithm to find the kth element in two sorted arrays
- Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
- 【随】Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack 问题解决。
- The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact
- Write an Efficient Method to Check if a Number is Multiple of 3
- Finding all elements(which are integer) in an array whose sum is equals to the element exists within
- The stack 'CSTACK' is filled to 92% (368 bytes used out of 400). The warning threshold is set to 90.%
- Using the isBranch() method to determine if a Tree item is a branch or leaf
- Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK(转
- Write an Efficient Method to Check if a Number is Multiple of 3(快速判断3的倍数)
- BUG: Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.
- Read Notify is the fastest, easiest, most reliable way to find out when email you've sent gets read.