CS61b_最小区间排序

 

 

 

   public static void zorkSort(int[] A, int k) {
      int i;
      int n = A.length;
      i = 0;
      PriorityQueue<Integer> pq = new PriorityQueue<>();
      while (i < k) {
         pq.add(A[i]);
         i++;
      }
      while (i < n) {
         A[i - k] = pq.remove(); // 在可以接收到范围内进行排序
         pq.add(A[i]);
         i += 1;
      }

      while (!pq.isEmpty()) { // 已经处理完前 (n - k) 个元素,接下来处理剩下的
         A[i - k] = pq.remove();
         i++;
      }
   }

 

posted @ 2023-05-27 21:53  哎呦_不想学习哟~  阅读(10)  评论(0)    收藏  举报