diff --git a/Sorting/Insertion Sort/insertion_sort.cpp b/Sorting/Insertion Sort/insertion_sort.cpp new file mode 100644 index 0000000..b50a0bd --- /dev/null +++ b/Sorting/Insertion Sort/insertion_sort.cpp @@ -0,0 +1,37 @@ +//insertion sort:it is a technique in which we start from 2nd element and compare it with the first element and put it in its proper place. +//this sorting technique is better than bubble sort and selection sort +//time complexity:O(n^2) +//space complexity:O(1) + +#include +using namespace std; + +void insertion_sort(int arr[],int n){ + int i,j,key; + for(int i=1;i=0 and arr[j]>key){ + arr[j+1]=arr[j]; + j=j-1; + } + arr[j+1]=key; + } +} + +void printing(int arr[],int n){ + for(int i=0;i