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

源代码在线查看: doubleandedgesortedondouble.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 DoubleAndEdgeSortedOnDouble				  implements ContentComparable				{				  private double m_double;				  private Edge m_edge;								  public DoubleAndEdgeSortedOnDouble( double p_double, Edge p_edge )				  {				    super();				    m_double = p_double;				    m_edge = p_edge;				  }								  public DoubleAndEdgeSortedOnDouble( DoubleAndEdgeSortedOnDouble that )				  {				    this( that.m_double, that.m_edge );				  }								  public double getDouble()				  {				    return m_double;				  }								  public Edge getEdge()				  {				    return m_edge;				  }								  public String toString()				  {				    return new String				    (				      "("				      + this.m_double				      + ","				      + this.m_edge.toString()				      + ")"				    );				  }								  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 < ( ( DoubleAndEdgeSortedOnDouble ) that).m_double				    )				    {				      return Sortable.THIS_LESS_THAN;				    }								    if				    (				      this.m_double > ( ( DoubleAndEdgeSortedOnDouble ) that).m_double				    )				    {				      return Sortable.THIS_GREATER_THAN;				    }								    return Sortable.THIS_EQUAL_TO;								  }								  public void swap ( Object l, Object r )				  {								    // rename for ease of use				    DoubleAndEdgeSortedOnDouble left = ( DoubleAndEdgeSortedOnDouble ) l;								    // rename for ease of use				    DoubleAndEdgeSortedOnDouble right = ( DoubleAndEdgeSortedOnDouble ) r;								    double doubleTemp;								    doubleTemp = left.m_double;				    left.m_double = right.m_double;				    right.m_double = doubleTemp;								    // Edges already have a swap routine, might as well use it.								    left.m_edge.swap( (Object) left.m_edge, (Object) right.m_edge);								/*				** 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_edge.contentIsTheSameAs( ( (DoubleAndEdgeSortedOnDouble) that ).getEdge() )				        )				        &&				        (				          this.m_double				          ==				          ( (DoubleAndEdgeSortedOnDouble) that ).getDouble()				        )				      );				  }								}											

相关资源