public static int[] sort_sagezk2(int[] nums) {
    final int LEN = nums.length;
    int i, j, t, p;
    int[] temp = new int[LEN];
    for (i = 0; i < LEN;) {
      temp[nums[i++]]++;
    }
    for (i = 0, p = 0; i < LEN; ++i) {
      if ((t = temp[i]) == 0)
        continue;
      for (j = 0; j < t; ++j) {
        nums[p++] = i;
      }
    }
    return nums;
  }
这是刚才在一个精华帖里看到的<【竞赛】排序算法的最快实现-继续>,有人能帮我解释下这程序吗?里面的temp[nums[i++]]++;是什么意思啊?temp的大小不是LEN吗?它的标号用另一个数组的值那是不很容易越界?谢谢了.

解决方案 »

  1.   

    是的,的确是这样。只要是int类型就可以
      

  2.   

    Yes, I think so. You can test this method with an array with short length but containing big int.
      

  3.   

    是不是只要nums[i++]中只要有一个数比LEN大就越界了?如果是这样的话这样写排序有什么意义啊,肯定是有其它精妙之处只是我不懂,有谁能注释下这个程序吗?先谢谢了.
      

  4.   

    Maybe you need to test it first. Because I have no IDE in company.
      

  5.   

    很明显,hash排序,效率最高,空间最费
      

  6.   

    好像是变化过的hash排序,是很容易溢出