您的位置:首页 > 其它

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);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐