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

📄 figure.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import dslib.list.LinkedListUos;

/**	A figure with a name and a list of shapes that make up the figure. */
public class Figure extends Shape
{
	/**	Name of the figure. */
	public String name;

	/**	Set the name to be newName. 
		Analysis: Time = O(1) */
	public void setName(String newName)
	{
		name = newName;
	}

	/**	The parts of the figure. */
	protected LinkedListUos parts;

	/**	Make a new figure with name newName.
		Analysis: Time = O(1) */
	public Figure(String newName)
	{
		name = newName;
		parts = new LinkedListUos();
		x = 0;
		y = 0;
	}

	/**	Add s as a part of the figure.
		Analysis: Time = O(1) */
	public void insert(Shape s)
	{
		parts.insertLast(s);
	}

	/**	Shift the position of each part of the figure by shiftX and shiftY. 
		Analysis: Time = O(number of parts of the figure) */
	public void shift(int shiftX, int shiftY)
	{
		super.shift(shiftX, shiftY);
		parts.goFirst();
		while (!parts.after())
		{
			((Shape) parts.item()).shift(shiftX, shiftY);
			parts.goForth();
		}
	}

	/**	String representation of the figure with indentation for nested parts. 
		Analysis: Time = O(number of parts to the figure) */
	public String toString()
	{
		String result = "\n" + indent + name + " has parts: ";
		indent += "     ";
		
		parts.goFirst();
		while (!parts.after())
		{
			result += parts.item();
			parts.goForth();
		}
		indent = indent.substring(0, indent.length() - 5);
		return result;
	}
}

⌨️ 快捷键说明

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