Java第七章分解.ppt

* 从想法到解决方案 for (int i = 0; i list.length; i++) { select the smallest element in list[i..listSize-1]; swap the smallest with list[i], if necessary; // list[i] is in its correct position. // The next iteration apply on list[i..listSize-1] } list[0] list[1] list[2] list[3] ... list[10] list[0] list[1] list[2] list[3] ... list[10] list[0] list[1] list[2] list[3] ... list[10] list[0] list[1] list[2] list[3] ... list[10] list[0] list[1] list[2] list[3] ... list[10] ... list[0] list[1] list[2] list[3] ... list[10] * 扩展为 for (int i = 0; i listSize; i++) { select the smallest element in list[i..listSize-1]; swap the smallest with list[i], if necessary; // list[i] is in its correct position. // The next iteration apply on list[i..listSize-1] } double currentMin = list[i]; int currentMinIndex = i; for (int j = i; j list.length; j++) { if (currentMin list[j]) { currentMin = list[j]; currentMinIndex = j; } } * 扩展为 for (int i = 0; i listSize; i++) { select the smallest element in list[i..listSize-1]; swap the smallest with list[i], if necessary; // list[i] is in its correct position. // The next iteration apply on list[i..listSize-1] } double currentMin = list[i]; int currentMinIndex = i; for (int j = i; j list.length; j++) { if (currentMin list[j]) { currentMin = list[j]; currentMinIndex = j; } } * 扩展为 for (int i = 0; i listSize; i++) { select the smallest element in list[i..listSize-1]; swap the smallest with list[i], if necessary; // list[i] is in its correct position. // The next iteration apply on list[i..listSize-1] } if (currentMinIndex != i) { list[currentMinIndex] = list[i]; list[i] = currentMin; } * 将它们放在一个方法中 /** The method for sorting the numbers */ public static void selec

文档评论(0)

1亿VIP精品文档

相关文档