Insertionsort (stella v0.7.0)

Documentation for Insertion sort algorithm. All important informations about counting sort you can find at Wikipedia page.

annotations

Annotations

  • n - number of elements in list

Link to this section Summary

Link to this section Functions

@spec run([integer()]) :: list()

Sort list

  • Worst-case performance: O(n^2)
  • Average performance: O(n^2)
  • Best-case performance: O(n) - for already sorted or empty lists

examples

Examples

iex> Insertionsort.run([4, 1, 3, 2])
[1, 2, 3, 4]

iex> Insertionsort.run([-7, 0, 0, -2, -3, 5, 2])
[-7, -3, -2, 0, 0, 2, 5]