我正在嘗試使用雙倍的score值屬性對我的自定義類染色體進行排序。這些染色體存儲在ArrayList中。我知道我必須使用一個比較器,但在過去一個小時內我在網上閱讀了很多不同的觀點,所以我完全困惑。對數組中的對象進行雙值排序
附加是我的代碼,如果有人能指出我在正確的方向,我將不勝感激。
public class Chromosome
{
public Gene[] genes;
public double score;
public Chromosome(int l)
{
genes = new Gene[l];
}
public int getLength()
{
return genes.length;
}
public void printChromo()
{
for(int i=0;i<this.genes.length;i++)
{
System.out.println(""+this.genes[i].teacher+","+
this.genes[i].lecture+","+
this.genes[i].room+","+
this.genes[i].time+"");
}
}
public void setScore(double score)
{
this.score=score;
}
public double getScore()
{
return this.score;
}
}
不知道該有所作爲,但成績只能是一個雙間,幷包括0.0〜1.0
發現,而這個問題谷歌「java double sort」用於我的遺傳alghorithm – sweetrenard