Class InsertionSortStrategy

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

public class InsertionSortStrategy extends Object implements SortStrategy
Implements the insertion sort algorithm as a sorting strategy.

This class implements the SortStrategy interface and provides a method to perform insertion 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 insertion sort algorithm.

      Insertion sort builds a sorted subarray from the front. It iterates from the second element to the last, inserting each into its correct position within the sorted subarray. Elements are compared and shifted backwards until the correct position is found.

      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:
      The sorted array.