arrayedsimplelistwithrecclone.java

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

JAVA
35
字号
import dslib.list.*;

/**	A variation of ArrayedSimpleListUos that has a recursive version of listClone(). */
public class ArrayedSimpleListWithRecClone extends ArrayedSimpleListUos
{
	/**	Construct a new list with the specified newCapacity. <br>
		Analysis: Time = O(newCapacity) <br>
		@param length capacity of the new list*/
	public ArrayedSimpleListWithRecClone(int newCapacity)
	{
		super(newCapacity);
	}

	/**	Return a list clone of this list. <br>
		Analysis: Time = O(capacity) */
	public SimpleListUos listClone()
	{
		if (isEmpty())
		{
			ArrayedSimpleListWithRecClone tempClone = (ArrayedSimpleListWithRecClone) clone();
			tempClone.rep = new Object[rep.length];
			return tempClone;
		}
		else
		{
			Object firstItem = firstItem();
			deleteFirst();
			SimpleListUos result = listClone();
			result.insertFirst(firstItem);
			insertFirst(firstItem);
			return result;
		}
	}
} 

⌨️ 快捷键说明

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