Beispiel #1
0
 public static int[] heapsort(int[] a) {
   Maxheap heap = new Maxheap(a.length);
   heap.arr = a;
   heap.heapsize = a.length;
   heap = heapify(heap);
   while (heap.heapsize >= 1) {
     int temp = heap.arr[0];
     heap.arr[0] = heap.arr[heap.heapsize - 1];
     heap.arr[heap.heapsize - 1] = temp;
     heap.heapsize--;
     heap.maxheapify(0);
   }
   a = heap.arr;
   return a;
 }
Beispiel #2
0
 public static Maxheap heapify(Maxheap heap) {
   int length = heap.heapsize;
   for (int i = (length - 2) / 2; i >= 0; i--) {
     heap.maxheapify(i);
   }
   return heap;
 }