private boolean sortByCost(Cost[] loopCostList, int[] loopIndex) { int maxlooptemp = loopCostList.length - 1; boolean exchanged = true; boolean permuted = false; while (exchanged) { // Bubble sort the LoopCosts. exchanged = false; for (int i = 0; i < maxlooptemp; i++) { int j = i + 1; Cost lci = loopCostList[i]; Cost lci1 = loopCostList[j]; if (lci1 == null) continue; if (lci.lessThan(lci1)) { int temp = loopIndex[i]; loopIndex[i] = loopIndex[j]; loopIndex[j] = temp; loopCostList[i] = lci1; loopCostList[j] = lci; exchanged = true; } } permuted |= exchanged; maxlooptemp--; } return permuted; }