权重加顺序号后排序

/*
        * 权重加顺序号后排序
        */
   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);
   }
}

 

你可能感兴趣的:(工作日志)