你写的那个排序有点乱,没搞明白~~~我把以前写的给你发一下- package cn.hncj.lianxi;
- public class SelectSortDemo {
- /**
- * @param args
- */
- public static void main(String[] args) {
- double[] list = {6.3,2.7,1.0,3.0};
- selectSort(list);
- StringBuilder sb = new StringBuilder();
- for(double d : list)
- {
- sb.append(d+",");
- }
- sb.deleteCharAt(sb.length()-1);
- System.out.println(new String(sb));
- }
-
- public static void selectSort(double[] list)
- {
- for(int x=0;x<list.length;x++)
- {
- for(int y=x;y<list.length;y++)
- {
- if(list[x]>list[y])
- swap(list,x,y);
-
- }
-
- }
- }
-
- private static void swap(double[] list,int a,int b)
- {
- double temp = list[a];
- list[a] = list[b];
- list[b] = temp;
-
- }
- }
复制代码 |