经典的货郎担问题解决办法

源代码在线查看: intdoublepairsortedondouble.java

软件大小: 1405 K
上传用户: kens
关键词:
下载地址: 免注册下载 普通下载 VIP

相关代码

								/*				** This code was written by Kent Paul Dolan.  See accompanying file				** TravellerDoc.html for status for your use.				*/								package com.well.www.user.xanthian.java.structures;								public class IntDoublePairSortedOnDouble				  implements ContentComparable				{				  private int m_int;				  private double m_double;								  public IntDoublePairSortedOnDouble( int p_int, double p_double )				  {				    super();				    m_int  = p_int;				    m_double = p_double;				  }								  public IntDoublePairSortedOnDouble( IntDoublePairSortedOnDouble that )				  {				    this( that.m_int, that.m_double );				  }								  public int getInt()				  {				    return m_int;				  }								  public double getDouble()				  {				    return m_double;				  }								  public String toString()				  {				    return new String				    (				      "(" + this.m_int + "," + this.m_double + ")"				    );				  }								  public int compareTo( Object that )				  {								/*				** We cannot even afford the cost of an if (DB) in a loop this hot, so				** comment out the debugging stuff.				*/								    if ( this.m_double < ( ( IntDoublePairSortedOnDouble ) that).m_double )				    {				      return Sortable.THIS_LESS_THAN;				    }								    if ( this.m_double > ( ( IntDoublePairSortedOnDouble ) that).m_double )				    {				      return Sortable.THIS_GREATER_THAN;				    }								    return Sortable.THIS_EQUAL_TO;								  }								  public void swap ( Object l, Object r )				  {				    IntDoublePairSortedOnDouble left  = ( IntDoublePairSortedOnDouble ) l;				    IntDoublePairSortedOnDouble right = ( IntDoublePairSortedOnDouble ) r;				    int intTemp;				    double doubleTemp;				    intTemp = left.m_int;				    doubleTemp = left.m_double;				    left.m_int = right.m_int;				    left.m_double = right.m_double;				    right.m_int = intTemp;				    right.m_double = doubleTemp;								/*				** We cannot even afford the cost of an if (DB) in a loop this hot, so				** comment out the debugging stuff.				*/								//      System.out.println				//      (				//        "Swapped " + left.toString() + " with " + right.toString()				//      );								  }								  public boolean contentIsTheSameAs( Object that )				  {				    return				      (				        this.m_int    == ( (IntDoublePairSortedOnDouble) that ).getInt()				        &&				        this.m_double == ( (IntDoublePairSortedOnDouble) that ).getDouble()				      );				  }								}							

相关资源