In this article |
---|
What is an Insertion sort |
Implement Insertion sort - Demo (JavaScript - C#) |
1 - What is an Insertion Sort
It is a sorting algorithm which sorts each Item in the list or array by shifting elements as they're encounter(one by one.)
In insertion sort we loop over an array from left to right and we compare current item in the iteration to it's left if it's less than pull it out and move the left index to the right then Insert current item to the sorted place . so everything left to the CurrentItem in the iteration Is sorted.
So let's see a sample implementation.