listtraverser.java

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

JAVA
39
字号
package simple;

/**	An abstract class to traverse a list and perform operations on the items along the
	way.  It has a process procedure which performs beforeActions, then iteratively
	performs itemActions on a list of items, and finally performs afterActions. */
public abstract class ListTraverser
{
	/**	Actions to be performed on each item. */
	public abstract void itemActions(Object x);

	/**	Actions to be performed before each traversal.
		Analysis: Time = O(1) */
	public void beforeActions() {}

	/**	Actions to be performed between items.
		Analysis: Time = O(1) */
	public void betweenActions() {}

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

	/**	Call itemAction on every item in the list.
		Analysis: Time = O(n), n = number of nodes */
	public void process(IteratedSimpleList target)
	{
		beforeActions();
		target.goFirst();
		while (!target.after())
		{
			itemActions(target.item());
			target.goForth();
			if (target.itemExists())
				betweenActions();
		}
		afterActions();
	}
}

⌨️ 快捷键说明

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