嘿伙计们感谢您以前的帮助,特别是对Sam我的帮助,几乎得到了这个工作,但由于家庭紧急情况不得不停止工作一段时间,一切似乎都在工作,除了一点保持原始指标:
int [] indices = new int [15];
for(int i=0; i<indices.length; i++){indices[i] = i;}
// Below code used for sorting
for (int i=0; i<distances.length; i++)
{
for(int j = i+1; j<distances.length; j++)
{
if (distances[i] > distances[j])
{
double temp = distances[j];
distances[j] = distances[i];
distances[i] = temp;
int tempindex = indices[i];
indices[j] = indices[i];
indices[i] = tempindex;
}
}
}
for (int i=1; i<distances.length; i++)
{
System.out.println("Point "+indices[i] + " -> " + distances[i]);
}
}
Sam我确实解释了如何做到这一点似乎无法让代码显示原始索引,所以有没有人有任何想法?
答案 0 :(得分:0)
不知道我是否理解你的问题。但我认为存在一个idex问题。
获取分配tempindex时使用的索引的战利品。
int tempindex = indices[i];
indices[j] = indices[i];
// tempindex is equal to indeices[i], so this instruction does nothing.
indices[i] = tempindex;
尝试更改
int tempindex = indices[i];
要
int tempindex = indices[j];