📄 listtraverser.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -