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

📄 twothreecursoruos.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
/* TwoThreeCursorUos.java
 * ---------------------------------------------
 * Copyright (c) 2001 University of Saskatchewan
 * All Rights Reserved
 * --------------------------------------------- */
 
package dslib.dictionary.twothreetree;

import dslib.base.*;
import dslib.exception.NoCurrentItemUosException;

/**	A cursor for the two-three tree data structures. */
public class TwoThreeCursorUos implements KeyedCursorUos
{

	/** The current node*/
	protected TwoThreeLeafUos node;
	
	/**	Is the cursor after the last item?. */
	protected boolean after;
	
	/**	Create a new cursor. <br>
		Analysis: Time = O(1) 
		@param newItemKey The key of the current item 
		@param newItem The current item */
	public TwoThreeCursorUos(TwoThreeLeafUos leaf, boolean isAfter)
	{
		after = isAfter;
		node = leaf;
	}

	/**	Is there a current item?. <br>
		Analysis: Time = O(1) */
	public boolean itemExists()
	{
		return node!=null;
	}	

	/**	The key of the current item. <br>
		Analysis: Time = O(1) <br>
		PRECONDITION: <br>
		<ul>
			itemExists()
		</ul> */	
	public Comparable itemKey() throws NoCurrentItemUosException
	{
		if (! itemExists())
			throw new NoCurrentItemUosException("No current item to delete.");
		return node.key();
	}
	
	/**	The current item. <br>
		Analysis: Time = O(1) <br>
		PRECONDITION: <br>
		<ul>
			itemExists()
		</ul>*/
	public Object item() throws NoCurrentItemUosException
	{
		if (! itemExists())
			throw new NoCurrentItemUosException("No current item to delete.");
		return node; 
	}

	/**	The current key-item pair. <br>
		PRECONDITION: <br>
		<ul>
			itemExists()
		</ul> */
	public PairUos keyItemPair() throws NoCurrentItemUosException
	{
		if (! itemExists())
			throw new NoCurrentItemUosException("No current item to delete.");
		return new PairUos(itemKey(), item());
	}

}

⌨️ 快捷键说明

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