发布网友 发布时间:2022-04-23 18:32
共1个回答
热心网友 时间:2023-10-13 02:03
这是java.util包下的Stack类,你可以看一下它是如何实现的,至于用法,无非就是push,pop,peek等操作等 /* * @(#)Stack.java 1.30 05/11/17 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.util; /** * The Stack class represents a last-in-first-out * (LIFO) stack of objects. It extends class Vector with five * operations that allow a vector to be treated as a stack. The usual * push and pop operations are provided, as well as a * method to peek at the top item on the stack, a method to test * for whether the stack is empty, and a method to search * the stack for an item and discover how far it is from the top. * <p> * When a stack is first created, it contains no items. * * <p>A more complete and consistent set of LIFO stack operations is * provided by the {@link Deque} interface and its implementations, which * should be used in preference to this class. For example: * {@code * Deque stack = new ArrayDeque();} * * @author Jonathan Payne * @version 1.30, 11/17/05 * @since JDK1.0 */ public class Stack extends Vector { /** * Creates an empty Stack. */ public Stack() { } /** * Pushes an item onto the top of this stack. This has exactly * the same effect as: * * addElement(item) * * @param item the item to be pushed onto this stack. * @return the item argument. * @see java.util.Vector#addElement