/** * @author Gaoxl * 根据key值排序,要求key值能够转为Long类型(快速排序) * @param maps * @param key * @return */ public static void sort(Map<String,Object>[] maps,String key,int start,int end){ if(start < end){ int mid = divide(maps,key,start,end); sort(maps,key,start,mid - 1); sort(maps,key,mid + 1,end); } } private static int divide(Map<String,Object>[] m ,String key, int start,int end){ int mid = (start + end) / 2; Map<String,Object> midValue = m[mid];//取中间位置值作为排序关键 m[mid] = m[start]; while(start < end){ while(start < end && (Long)m[end].get(key) >= (Long)midValue.get(key)) --end; if(end > start){ m[start] = m[end]; ++ start; } while(start < end && (Long)m[start].get(key) <= (Long)midValue.get(key)) ++start; if(start < end){ m[end] = m[start]; -- end; } } m[start] = midValue; return start; }
原文地址:https://www.cnblogs.com/lin0/p/12009911.html
时间: 2024-10-03 15:14:01