我有一組 srting 算法的值。我已經(jīng)成功地將它們整理出來(lái)。但我也想在排序后為每個(gè)元素提供索引。例如像: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我使用以下邏輯進(jìn)行排序。但無(wú)法獲得索引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; }
java中帶索引的排序算法
胡說(shuō)叔叔
2021-06-28 17:59:20