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

📄 comparablepairuos.java

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

/**	A descendant of PairUos which defines comparison for two pairs whereby the
	first items are compared first, and if they are equal, the second items are
	compared. */
public class ComparablePairUos extends PairUos implements Comparable
{
	/**	Constructor of the class 
		Analysis: Time = O(1) */
	public ComparablePairUos(Object o1, Object o2)
	{
		super(o1, o2);
	}
	
	/**	Redefine compareTo method by comparing the key values
		Analysis: Time = O(1) */
	public int compareTo(Object other)
	{
		Comparable first = (Comparable)((ComparablePairUos)other).firstItem();
		Comparable second = (Comparable)((ComparablePairUos)other).secondItem();
		if(((Comparable)firstItem()).compareTo(first) == 0)
			return ((Comparable)secondItem()).compareTo(second);
		else
			return ((Comparable)firstItem()).compareTo(first);
	}	
}

⌨️ 快捷键说明

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