我认为我的代码是自我解释的。
public Town[] GetShortestDistanceBetweenTowns() {
Town[] allTowns = getTowns();
Town[] bestPath = allTowns;
int bestDistance = CalculateDistance(bestPath);
int newDistance = bestDistance;
//shuffle allTowns array and look for best distance
for(int i=0; i<100; i++) {
MixArray(allTowns);
newDistance = CalculateDistance(allTowns);
if (newDistance < bestDistance) {
bestPath = allTowns;
bestDistance = newDistance;
}
}
return bestPath;
}
问题是,当我使用MixArray(allTowns)
时,它也会改变我的bestPath
数组的顺序。我想在这个数组中只保留最佳顺序。我该怎么办?
答案 0 :(得分:3)
import pandas as pd
toclean = pd.ExcelFile(r'C:\Users\Desktop\New Microsoft Excel Worksheet.xlsx',sheetname=0)
df4 = toclean.drop_duplicates(subset='A', keep='last')
df4.save(r'C:\Users\Desktop\final.xlsx')
是一种引用类型,因此Town
表示Town[] bestPath = allTowns;
始终与bestPath
匹配。要复制,您可以为allTowns
类实现IClonable,或者只是添加一个复制函数,用于创建具有重复值的新Town
。
这是一篇关于参考与价值类型的精彩文章: http://www.albahari.com/valuevsreftypes.aspx