标签:des style c class blog code
1 int[] arr = {1,4,2,5,7,3}; 2 int temp = 0; 3 //升序 4 for (int i = arr.length-1; i > 0; --i) { 5 for (int j = 0; j < i; ++j) { 6 if(arr[j+1] < arr[j]){ 7 temp = arr[j]; 8 arr[j] = arr[j+1]; 9 arr[j+1] = temp; 10 } 11 } 12 } 13 14 //降序 15 for (int i = 0; i < arr.length; i++) { 16 for (int j = arr.length-1; j > i; j--) { 17 if(arr[j] > arr[j-1]){ 18 temp = arr[j]; 19 arr[j] = arr[j-1]; 20 arr[j-1] = temp; 21 } 22 } 23 }
写的一个例子:
1 /** 2 * 说明:按成交率升序排序,成交率相同则按照成交单数排序 3 */ 4 private List<ProductDealRateInfo> sort(List<ProductDealRateInfo> list){ 5 ProductDealRateInfo temp = null; 6 for (int i = list.size()-1; i > 0; --i) { 7 for (int j = 0; j < i; ++j) { 8 if((list.get(j+1).getDealRate() < list.get(j).getDealRate()) || (list.get(j+1).getDealRate()==list.get(j).getDealRate() && list.get(j+1).getDealCount()<list.get(j).getDealCount())){ 9 temp = list.get(j); 10 list.set(j, list.get(j+1)); 11 list.set(j+1, temp); 12 } 13 } 14 } 15 return list; 16 } 17 18 /** 19 * 说明:按成交率降序排序,成交率相同则按照成交单数排序 20 */ 21 private List<ProductDealRateInfo> sortDesc(List<ProductDealRateInfo> list){ 22 ProductDealRateInfo temp = null; 23 for (int i = 0; i < list.size(); i++) { 24 for (int j = list.size()-1; j > i; j--) { 25 if((list.get(j).getDealRate() > list.get(j-1).getDealRate()) || (list.get(j).getDealRate()==list.get(j-1).getDealRate() && list.get(j).getDealCount()>list.get(j-1).getDealCount())){ 26 temp = list.get(j); 27 list.set(j, list.get(j-1)); 28 list.set(j-1, temp); 29 } 30 } 31 } 32 return list; 33 }
标签:des style c class blog code
原文地址:http://www.cnblogs.com/yl-fighting/p/3746298.html