pair.java

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

JAVA
33
字号
/**	This class represents a pair of objects. */
public class Pair
{
	/**	The first item of the pair. */
	public Object firstItem;

	/**	The second item of the pair. */
	public Object secondItem;

	/**	Create a pair with initial values v1 and v2. 
		Analysis: Time = O(1) */
	public Pair(Object v1, Object v2)
	{
		firstItem = v1;
		secondItem = v2;
	}

	/**	String representation of the pair.
		Analysis: Time = O(1) */
	public String toString()
	{
		return ( "(" + firstItem + "," + secondItem + ")" );
	}

	/**	Does this pair have equal variable values as the pair referenced by other? 
		Analysis: Time = O(1) */
	public boolean equals(Object other)
	{
		Pair otherPair = (Pair) other;
		return firstItem == otherPair.firstItem && secondItem == otherPair.secondItem;
	}
} 

⌨️ 快捷键说明

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