listtraverseruos.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 50 行

JAVA
50
字号
/* ListTraverserUos.java
 * ---------------------------------------------
 * Copyright (c) 2001 University of Saskatchewan
 * All Rights Reserved
 * --------------------------------------------- */
 
package dslib.list;

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

/**	Base class for processing every item in a list.
	Subclasses need only define itemAction. */
public abstract class ListTraverserUos
{
	/**	Actions to be performed before each traversal. <br>
		Analysis: Time = O(1) */
	public void beforeActions() 
	{
	}

	/**	Actions to be performed after each traversal. <br>
		Analysis: Time = O(1) */
	public void afterActions() 
	{
	}
	

	/**	Call itemAction for every item in the list. <br>
		Analysis: Time = O(n), where n = number of nodes 
		@param target position of item to be processed */
	public void process(LinearIteratorUos target)
	{
		beforeActions();
		target.goFirst();

		while (target.itemExists())
		{
			itemAction(target.item());
			target.goForth(); 						
		}
		afterActions();
	}

	/**	Perform an action on the specified item.
		@param item item to perform the action on */
	public abstract void itemAction(Object item);

} 

⌨️ 快捷键说明

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