⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liststack.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
package stacks;

import dslib.base.DispenserUos;
import dslib.list.LinkedSimpleListUos;
import dslib.exception.*;

/**	A Dispenser for items of type Object with the last in, first out 
	structure typical of a stack. item() refers to the top of the stack and
	can be deleted. It is implemented by inheriting LinkedSimpleListUos. */
public class ListStack extends LinkedSimpleListUos implements DispenserUos
{
	/**	Create a new ListStack object. 
		Analysis: Time = O(1) */
	public ListStack() {}

	/**	Insert x onto the top of this stack.
		Analysis: Time = O(1) */
	public void insert(Object x)
	{
		insertFirst(x);
	}

	/**	The item at the top of the stack.
		Analysis: Time = O(1) 
		PRECONDITION: 
			!isEmpty() */
	public Object item() 
	{
		return firstItem();
	}

	/**	Is there a current item?
		Analysis: Time = O(1) */
	public boolean itemExists()
	{
		return !isEmpty();
	}

	/**	Delete the item on the top of this stack.
		Analysis: Time = O(1) 
		PRECONDITION:
			!isEmpty() */
	public void deleteItem() throws ContainerEmptyUosException
	{
		if (isEmpty())
			throw new ContainerEmptyUosException("There is no current item to delete");

		deleteFirst();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -