当前位置: 首页 > news >正文

网站插件代码下载韩国网页设计网站

网站插件代码下载,韩国网页设计网站,小程序注册认证流程,中企动力建设的网站如何修改转载自 java.util.Stack类简介 Stack是一个后进先出#xff08;last in first out#xff0c;LIFO#xff09;的堆栈#xff0c;在Vector类的基础上扩展5个方法而来 Deque#xff08;双端队列#xff09;比起Stack具有更好的完整性和一致性#xff0c;应该被优先使用…转载自  java.util.Stack类简介 Stack是一个后进先出last in first outLIFO的堆栈在Vector类的基础上扩展5个方法而来 Deque双端队列比起Stack具有更好的完整性和一致性应该被优先使用 E push(E item)             把项压入堆栈顶部。    E pop()             移除堆栈顶部的对象并作为此函数的值返回该对象。    E peek()             查看堆栈顶部的对象但不从堆栈中移除它。    boolean empty()             测试堆栈是否为空。     int search(Object o)             返回对象在堆栈中的位置以 1 为基数。 Stack本身通过扩展Vector而来而Vector本身是一个可增长的对象数组 a growable array of objects那么这个数组的哪里作为Stack的栈顶哪里作为Stack的栈底 答案只能从源代码中寻找jdk1.6 public class StackE extends VectorE { /** * Creates an empty Stack. */ public Stack() { } /** * Pushes an item onto the top of this stack. This has exactly * the same effect as: * blockquotepre * addElement(item)/pre/blockquote * * param item the item to be pushed onto this stack. * return the codeitem/code argument. * see java.util.Vector#addElement */ public E push(E item) { addElement(item); return item; } /** * Removes the object at the top of this stack and returns that * object as the value of this function. * * return The object at the top of this stack (the last item * of the ttVector/tt object). * exception EmptyStackException if this stack is empty. */ public synchronized E pop() { E obj; int len size(); obj peek(); removeElementAt(len - 1); return obj; } /** * Looks at the object at the top of this stack without removing it * from the stack. * * return the object at the top of this stack (the last item * of the ttVector/tt object). * exception EmptyStackException if this stack is empty. */ public synchronized E peek() { int len size(); if (len 0) throw new EmptyStackException(); return elementAt(len - 1); } /** * Tests if this stack is empty. * * return codetrue/code if and only if this stack contains * no items; codefalse/code otherwise. */ public boolean empty() { return size() 0; } /** * Returns the 1-based position where an object is on this stack. * If the object tto/tt occurs as an item in this stack, this * method returns the distance from the top of the stack of the * occurrence nearest the top of the stack; the topmost item on the * stack is considered to be at distance tt1/tt. The ttequals/tt * method is used to compare tto/tt to the * items in this stack. * * param o the desired object. * return the 1-based position from the top of the stack where * the object is located; the return value code-1/code * indicates that the object is not on the stack. */ public synchronized int search(Object o) { int i lastIndexOf(o); if (i 0) { return size() - i; } return -1; } /** use serialVersionUID from JDK 1.0.2 for interoperability */ private static final long serialVersionUID 1224463164541339165L; } 通过peek()方法注释The object at the top of this stack (the last item of the Vector object可以发现数组Vector的最后一位即为Stack的栈顶 pop、peek以及search方法本身进行了同步 push方法调用了父类的addElement方法 empty方法调用了父类的size方法 Vector类为线程安全类 综上Stack类为线程安全类(多个方法调用而产生的数据不一致问题属于原子性问题的范畴) public class Test { public static void main(String[] args) { StackString s new StackString(); System.out.println(------isEmpty); System.out.println(s.isEmpty()); System.out.println(------push); s.push(1); s.push(2); s.push(3); Test.it(s); System.out.println(------pop); String str s.pop(); System.out.println(str); Test.it(s); System.out.println(------peek); str s.peek(); System.out.println(str); Test.it(s); System.out.println(------search); int i s.search(2); System.out.println(i); i s.search(1); System.out.println(i); i s.search(none); System.out.println(i); } public static void it(StackString s){ System.out.print(iterator:); IteratorString it s.iterator(); while(it.hasNext()){ System.out.print(it.next();); } System.out.print(\n); } } 结果 ------isEmpty   true             ------push   iterator:1;2;3;     ------pop   3       --栈顶是数组最后一个   iterator:1;2;   ------peek   2       --pop取后删掉peek只取不删   iterator:1;2;   ------search       1       --以1为基数即栈顶为1   2       --和栈顶见的距离为2-11   -1      --不存在于栈中   Stack并不要求其中保存数据的唯一性当Stack中有多个相同的item时调用search方法只返回与查找对象equal并且离栈顶最近的item与栈顶间距离见源码中search方法说明
http://www.pierceye.com/news/707234/

相关文章:

  • 深圳企业网站建设服务平台销售推广语
  • 做网站要什么资料百度网盘登录
  • 聚牛网站建设公司北京seo优化推广
  • 成都网站公司网站建设东莞大岭山电子厂
  • python建立简易网站网站界面设计的分类有哪几种
  • 网络规划师考哪些内容优化设计卷子答案
  • 邢台网站关键词优化wordpress弹窗下载
  • 晋城市企业网站腾讯qq官网登录入口
  • 怎么给网站在百度地图上做爬虫一家专门做灯的网站
  • 河南焦作有做网站开发的公司吗xampp安装wordpress
  • python购物网站开发流程图win淘宝客wordpress主题模板
  • 江苏省建设执业网站个人做淘宝客网站有哪些
  • 浙江省建设厅门户网站咨询公司是干什么的
  • 哪个网站上可以做初中数学题wordpress 网校插件
  • html写手机网站制作网页用什么语言
  • 一站式网站建设价格百度网站
  • 招商网站建设多少钱企业形象墙
  • 医疗设备响应式网站免费素材库
  • 服务器如何搭建php网站网页美工设计从入门到精通
  • 淘宝的网站建设情况做企业平台的网站有哪些
  • 深圳网站建设公司设计公司做网站排名有用吗
  • 企业营销型网站建设厂家 天堂资源地址在线官网
  • 编写这个网站模板要多少钱便宜做网站公司
  • asp企业网站源码下载网页制作基础教程田田田田田田田田
  • 网站标题title怎么写网站建设建设公司有哪些
  • 辽宁移动网站网站域名注册费用
  • 深圳建网站兴田德润专业电商店铺首页设计
  • 网站推广的工作内容芜湖做网站的客户
  • 求一些做里番的网站wordpress新闻快讯插件
  • 网站加速器下载公司网页设计思路