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

📄 testcodefloatandboxdic.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
public class TestCodeFloatAndBoxDic
{
	public TestCodeFloatAndBoxDic()
	{
		codeFloatDictionary();
		codeBoxDictionary();
	}
	
	public void codeFloatDictionary()
	{
		/*	Create a dictionary and insert four Float values. */
		ArrayedBasicDictionary floatDictionary = new ArrayedBasicDictionary(10);
		floatDictionary.insert(new Float(5.7));
		floatDictionary.insert(new Float(9.3));
		floatDictionary.insert(new Float(-4.8));
		floatDictionary.insert(new Float(12.7));

		/*	Delete the objects with values 9.3 and 12.7. */
		Float f = new Float(9.3);
		if (floatDictionary.has(f))
			floatDictionary.delete(f);
		floatDictionary.delete(new Float(12.7));

		/*	Obtain the object with value 5.7, convert it to type Float, and retrieve
			its value as an int. */
		int i = ((Float) floatDictionary.obtain(new Float(5.7))).intValue();
		System.out.println("Output from codeFloatDictionary\n" + floatDictionary.toString());
	}
	
	public void codeBoxDictionary()
	{
		/*	Create a dictionary and insert three BetterBasicboxes. */
		ArrayedBasicDictionary boxDictionary = new ArrayedBasicDictionary(10);
		BetterBasicBox bbox1 = new BetterBasicBox(1, 11, 21);
		boxDictionary.insert(bbox1);
		BetterBasicBox bbox2 = new BetterBasicBox(2, 12, 22);
		boxDictionary.insert(bbox2);
		BetterBasicBox bbox3 = new BetterBasicBox(3, 13, 23);
		boxDictionary.insert(bbox3);
		
		/*	If the dictionary has a box with dimensions 2, 12, and 22, then delete it. */
		BetterBasicBox bbox4 = new BetterBasicBox(2, 12, 22);
		if (boxDictionary.has(bbox4))
			boxDictionary.delete(bbox4);
			
		/*	Obtain the box from the dictionary with dimensions 1, 11, and 21. */
		Object obj;
		obj = boxDictionary.obtain(new BetterBasicBox(1, 11, 21)); 
		BetterBasicBox bbox5 = (BetterBasicBox) obj;

		/*	Change the definition of equality in the dictionary to compare
			boxes by reference. */
		boxDictionary.compareObjectReferences();
		if (boxDictionary.has(bbox5))
			boxDictionary.delete(bbox5);

		/*	The next three statements do not delete a box, as bbox6 references a new
			box, so it will never be found in the dictionary using reference equality. */
		BetterBasicBox bbox6 = new BetterBasicBox(3, 13, 23);
		if (boxDictionary.has(bbox6))
			boxDictionary.delete(bbox3);
		System.out.println("Output from codeBoxDictionary\n" + boxDictionary.toString());
	}
	
	public static void main(String[] args)
	{
		new TestCodeFloatAndBoxDic();
	}
}

⌨️ 快捷键说明

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