我有一组 srting 算法的值。我已经成功地将它们整理出来。但我也想在排序后为每个元素提供索引。例如像:
Array = [95, 53, 24, 10]
Output after sorting should be like :
10 at index 3, 24 at index 2, 53 at index 1 and 95 at index 0
我使用以下逻辑进行排序。但无法获得索引
for (int p = 0; p < ((list.size()) - 1); p++) {
int min = p;
count++;
for(int q=p+1; q<list.size();q++) {
if(doubleArray[q] < doubleArray[min]) {
min = q;
}
}
double smallNumber = doubleArray[p];
doubleArray[p] = doubleArray[min];
doubleArray[min] = smallNumber;
}
呼啦一阵风
相关分类