From 7db0ea26486946d1383919dc3a537826228ed408 Mon Sep 17 00:00:00 2001 From: Raghav Gupta Date: Mon, 18 Oct 2021 11:47:20 +0530 Subject: [PATCH 1/2] Create Insertion_sort --- Algorithms/Insertion_sort | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Algorithms/Insertion_sort diff --git a/Algorithms/Insertion_sort b/Algorithms/Insertion_sort new file mode 100644 index 0000000..47beca6 --- /dev/null +++ b/Algorithms/Insertion_sort @@ -0,0 +1,34 @@ +#include +using namespace std; +void display(int *array, int size) { + for(int i = 0; i 0 && array[j-1]>key) { + array[j] = array[j-1]; + j--; + } + array[j] = key; //insert in right place + } +} +int main() { + int n; + cout << "Enter the number of elements: "; + cin >> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + insertionSort(arr, n); + cout << "Array after Sorting: "; + display(arr, n); +} From 47cc93f52d10b1007914dcacdada8051e9c2cf5a Mon Sep 17 00:00:00 2001 From: Raghav Gupta Date: Mon, 18 Oct 2021 11:47:50 +0530 Subject: [PATCH 2/2] Rename Insertion_sort to Insertion_sort.cpp --- Algorithms/{Insertion_sort => Insertion_sort.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Algorithms/{Insertion_sort => Insertion_sort.cpp} (100%) diff --git a/Algorithms/Insertion_sort b/Algorithms/Insertion_sort.cpp similarity index 100% rename from Algorithms/Insertion_sort rename to Algorithms/Insertion_sort.cpp