From 0f5df32223fa976f92d66caa6151c91ae6b2b66e Mon Sep 17 00:00:00 2001 From: kasthuri28 Date: Wed, 9 Sep 2020 07:25:07 +0530 Subject: [PATCH] Insertion sort in cpp --- insertionSort.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 insertionSort.cpp diff --git a/insertionSort.cpp b/insertionSort.cpp new file mode 100644 index 0000000..506fd45 --- /dev/null +++ b/insertionSort.cpp @@ -0,0 +1,32 @@ +#include +using namespace std; + +void insertion(int n, int a[]){ + int key,j; + for(int i=1;i=0 && a[j]>key){ + a[j+1] = a[j]; + j--; + } + a[j+1]=key; + } +} + +int main(){ + int n; + cout<<"Enter the size of the array : "; + cin>>n; + int a[n]; + cout<<"Enter the array elements\n"; + for(int i=0;i>a[i]; + } + insertion(n,a); + cout<<"The sorted array is : "; + for(int j=0;j