java.lang.Object
com.github.rlacher.sortbench.strategies.implementations.HeapSortStrategy
All Implemented Interfaces:
SortStrategy

public class HeapSortStrategy extends Object implements SortStrategy
Implements the heap sort algorithm as a sorting strategy.

This class implements the SortStrategy interface and provides a method to perform heap sort on an array of integers.

  • Constructor Details

  • Method Details

    • sort

      public BenchmarkMetric sort(int[] array)
      Sorts the provided array in ascending order using the heap sort algorithm.

      Summary of heap sort algorithm: Heap Sort initially builds a max heap from the input array using buildMaxHeap(int[]). It then repeatedly extracts the maximum element (the root of the heap) and places it at the end of the array. After each extraction, the heap property is restored for the remaining elements through a heapify(int[], int, int) operation. This continues until the entire array is sorted in ascending order.

      Input array validation is assumed to be performed by the calling Sorter class.

      Specified by:
      sort in interface SortStrategy
      Parameters:
      array - The array to be sorted.
      Returns:
      A BenchmarkMetric containing performance information about the sorting process.
      Throws:
      NullPointerException - If array is null (should not happen).