From 957b57cf60267d0018a3901bbf9ae20b6054c57f Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Wed, 1 Jul 2020 10:10:51 -0400 Subject: [PATCH] fix issues from #929 --- sorting/insertion_sort.cpp | 106 +++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/sorting/insertion_sort.cpp b/sorting/insertion_sort.cpp index 39298eb45..4bfce9ce6 100644 --- a/sorting/insertion_sort.cpp +++ b/sorting/insertion_sort.cpp @@ -4,22 +4,18 @@ * \brief [Insertion Sort Algorithm * (Insertion Sort)](https://en.wikipedia.org/wiki/Insertion_sort) * - * \author - * * \details * Insertion sort is a simple sorting algorithm that builds the final * sorted array one at a time. It is much less efficient compared to * other sorting algorithms like heap sort, merge sort or quick sort. * However it has several advantages such as - *
- * 1 - easy to implement - * 2 - For small set of data it is quite efficient - * 3 - More efficient that other Quadratic complexity algorithms like - * Selection sort or bubble sort. - * 4 - It's stable that is it does not change the relative order of - * elements with equal keys - * 5 - Works on hand means it can sort the array or list as it receives. - *+ * 1. easy to implement + * 2. For small set of data it is quite efficient + * 3. More efficient that other Quadratic complexity algorithms like + * Selection sort or bubble sort. + * 4. It's stable that is it does not change the relative order of + * elements with equal keys + * 5. Works on hand means it can sort the array or list as it receives. * * It is based on the same idea that people use to sort the playing cards in * their hands. @@ -27,44 +23,41 @@ * of elements as soon as we find a unsorted element that is a misplaced * element we place it at a sorted position. * - * Suppose initially we have - *
- * 4 3 2 5 1 - * - * we start traversing from 4 till we reach 1 + * Execution example steps: + * 1. Suppose initially we have + *- * + *4 3 2 5 1+ * 2. We start traversing from 4 till we reach 1 * when we reach at 3 we find that it is misplaced so we take 3 and place * it at a correct position thus the array will become - * - * 3 4 2 5 1 - * - * in the next iteration we are at 2 we find that this is also misplaced so + *3 4 2 5 1+ * 3. In the next iteration we are at 2 we find that this is also misplaced so * we place it at the correct sorted position thus the array in this iteration * becomes - * - * 2 3 4 5 1 - * - * we does not do anything with 5 and move on to the next iteration and select - * 1 which is misplaced and place it at correct position. Thus, we have - * - * 1 2 3 4 5 - *
2 3 4 5 1+ * 4. we does not do anything with 5 and move on to the next iteration and + * select 1 which is misplaced and place it at correct position. Thus, we have + *
1 2 3 4 5*/ #include