`
liuzhaomin
  • 浏览: 199586 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Stack

JDK 
阅读更多

Stack基于Vector实现,支持LIFO。实际上栈是一种抽象数据类型。

 

public
class Stack<E> extends Vector<E> {
    /**
     * Creates an empty Stack.
     */
    public Stack() {
    }

    /**
     * Pushes an item onto the top of this stack. This has exactly
     * the same effect as:
     * <blockquote><pre>
     * addElement(item)</pre></blockquote>
     *
     * @param   item   the item to be pushed onto this stack.
     * @return  the <code>item</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 <tt>Vector</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 <tt>Vector</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  <code>true</code> if and only if this stack contains
     *          no items; <code>false</code> otherwise.
     */
    public boolean empty() {
	return size() == 0;
    }

    /**
     * Returns the 1-based position where an object is on this stack.
     * If the object <tt>o</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 <tt>1</tt>. The <tt>equals</tt>
     * method is used to compare <tt>o</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;
}

 

 

分享到:
评论

相关推荐

    C语言头文件 STACK

    C语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 STACKC语言头文件 ...

    redis-stack-server 7.2.0 安装包合集

    redis-stack-server-7.2.0-v9.arm64.snap redis-stack-server-7.2.0-v9.bionic.arm64.tar.gz redis-stack-server-7.2.0-v9.bionic.x86_64.tar.gz redis-stack-server-7.2.0-v9.bullseye.x86_64.tar.gz redis-stack-...

    Full-Stack React Projects

    The benefits of using a full JavaScript stack for web development are undeniable, especially when robust and widely adopted technologies such as React, Node, and Express and are available. Combining ...

    Pro MEAN Stack Development(Apress,2016).pdf

    Using the MEAN stack – MongoDB, ExpressJS, AngularJS, and Node.js – you will get the tools you need to set up, write your code once, and be able to deploy your code on any device. You will be able ...

    ELK Stack权威指南 第2版

    ELKstack是Elasticsearch、Logstash、Kibana三个开源软件的组合,是目前开源界流行的实时数据分析方案,成为实时日志处理领域开源界的选择。然而,ELKstack也并不是实时数据分析界的灵丹妙药,使用不恰当,反而会...

    Haskell入门:用stack搭建haskell编译环境

    stack官方网站: https://docs.haskellstack.org/en/stable/README/ 首先: 在终端下键入下面这条命令: curl -sSL https://get.haskellstack.org/ | sh 出现以下情况: 在终端下输入命令: sudo apt install curl...

    Toshiba Bluetooth Stack v8.00.03(T) 补丁

    Toshiba Bluetooth Stack v8.00.03(T) 补丁,Toshiba Bluetooth Stack v8.00.04(T)也可以用。 日发现东芝的蓝牙驱动软件升级到 v8.00.03(T) 版本了,新版本除了修复了一些BUG,更是增加了对蓝牙3.0的支持,建议使用...

    Stack Stack的实现

    Stack Stack的实现

    full stack javascript development

    MEAN stack. This book will explore the MEAN stack in detail. We’ll begin by covering Node.js, as it lays the groundwork for all our server-side work. You will learn how to get Node running on...

    Z-Stack 3.0.1

    Z-Stack 3.0.x is TI's Zigbee 3.0 compliant protocol suite for the CC2530, CC2531, and CC2538 Wireless MCU. Supports the CC2592 and CC2590 RF front ends which extend up to +22dBm and +14dBm transmit ...

    fullstack react book

    fullstack react book, 学习react比较全的书,这是花钱买的

    基于Z-Stack的点对点通信_zigbeecc2530_z-stack_

    CC2530 Z-stack

    Beginning.Elastic.Stack

    This book teaches you how to install, configure and implement the Elastic Stack (Elasticsearch, Logstash and Kibana) – the invaluable tool for anyone deploying a centralized log management solution ...

    Stack-栈实例

    栈的实现,Stack栈使用符号进出 静态栈,与链表栈的实例

    数据结构stack代码完整版

    数据结构中stack的详细编码及使用 改代码中包含了stack的初始,添加,删除,修改,销毁以及一些简单应用的代码

    Pro MERN Stack(Apress,2017)

    Assemble the complete stack required to build a modern web app using React: MongoDB (a NoSQL database) and Express (a framework for web application servers), which runs on Node (JavaScript on the ...

    Stack 栈 C语言实现

    可运行C语言版本参考...#include "stack.h" /** * position */ typedef struct { int x; int y; }Pos; /** * the maze struct */ typedef struct { int sno; Pos coordinate; int dir; }Element ; .......

    华为云Stack 6.5.0 API开发指南

    华为云Stack解决方案API接口统一通过API网关对外提供服务,用户需要基于华为云Stack做应用/云平台开发时,可以直接调用API网关上开放的API组件API。华为云Stack解决方案API分认证、运维、运营、IaaS、PaaS、BC&DR...

Global site tag (gtag.js) - Google Analytics