🧰 Developer’s toolbox: 🗳️ Insertion Sort

Vee Lesyk
Dots and Spaces
Published in
1 min readSep 17, 2019
Insertion Sort.

Wikipedia says:

Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and mostly sorted lists, and is often used as part of more sophisticated algorithms. It works by taking elements from the list one by one and inserting them in their correct position into a new sorted list similar to how we put money in out wallet. In arrays, the new list and the remaining elements can share the array’s space, but insertion is expensive, requiring shifting all following elements over by one. Shellsort (see below) is a variant of insertion sort that is more efficient for larger lists.

Github repo: link.

Swift

InsertionSort.swift

TypeScript

InsertionSort.ts

Output

Insertion Sort Output.
Insertion.

P.S. We would be happy to see comments according to mistakes & typos.

--

--

Vee Lesyk
Dots and Spaces

#h+ #livemoredomore Adventurer. Unique experience wizard. Maker of things. Convergence commander. Information warlock. Problem solver. System: ☉; Planet: ♁.