单选题

考虑以下JAVA排序代码,对于array为{15,0,6,9,3}时,运行...

发布于 2022-03-03 13:57:15

考虑以下JAVA排序代码,对于array为{15,0,6,9,3}时,运行sort方法,则最终排序结果为:
 public void sort(Comparable[] a) {
  int N = a.length
  int h = 1
  while (h < N / 3) {
   h = 3 * h + 1// 1, 4, 13, 40, ...
  }
  while (h >= 1) {
   for (int i = h i < N i++) {
     for (int j = i  j >= h && compareElement(a[j],  a[j - h]) j -= h) {
      exch(a, j, j - h)
    }
   }
   h = h / 3
  }
 }
 
 public boolean compareElement(Comparable v, Comparable w) {
  return v.compareTo(w) < 0
 }

 public static void exch(Comparable[] a, int i, int j) {
  Comparable t = a[i]
  a[i] = a[j]
  a[j] = t
 }

登录后免费查看答案
关注者
0
被浏览
16
知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看