From b6d419aa357eb733cec433160361ee987d4a7bd0 Mon Sep 17 00:00:00 2001 From: abdurrezzak Date: Fri, 20 Oct 2017 21:54:42 +0300 Subject: [PATCH] Add files via upload --- 2.InsertionSort.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 2.InsertionSort.cpp diff --git a/2.InsertionSort.cpp b/2.InsertionSort.cpp new file mode 100644 index 0000000..cd601e9 --- /dev/null +++ b/2.InsertionSort.cpp @@ -0,0 +1,44 @@ +/* + * This program takes an array from the user + * sorts it using insertion sort + * Prints the sorted array + * For more information about Insertion Sort Algorithm: https://en.wikipedia.org/wiki/Insertion_sort + * + * Coded by: Abdurrezak EFE + * + * */ +#include +#include +using namespace std; + +void insertion_sort(int arr[],int k) //insertion sort function +{ + for(int i=1;i=0 && arr[j]>=num) + { + arr[j+1] = arr[j]; + j = j-1; + } + arr[j+1] = num; + } +} + +int main() +{ + int k; + cout << "Enter the number of the integers you want to construct the array from: "; + cin >> k; + + int arr[k]; + for(int i=0;i> arr[i]; + + insertion_sort(arr,k); //sorting + + for(int i=0;i