/* * 权重加顺序号后排序 */ public static void sort(String[] strs,int[] weight){ int[] nums = new int[strs.length]; for (int i = 1; i < strs.length; i++) { nums[i] = weight[i] + i; } if (strs.length != nums.length) { return; } Holder[] holders = new Holder[strs.length]; for (int i = 0; i < strs.length; i++) { holders[i] = new Holder(strs[i], nums[i]); } Arrays.sort(holders); for (Holder holder : holders) { System.out.print(holder.str); } System.out.println(); } public static void main(String[] args) throws Exception { String[] strs = {"A", "B", "C", "D", "E", "F", "G", "H"}; int[] a = {7, 5, 3, 2, 6, 1, 4, 9}; sort(strs, a); } }
java 权重加顺序号后排序
最新推荐文章于 2024-05-22 12:43:45 发布