From 8b2b00e72584dafdb86213dfa844b5c7771fe6ae Mon Sep 17 00:00:00 2001 From: sajalgupta Date: Fri, 7 Oct 2022 11:11:31 +0530 Subject: [PATCH 1/2] added insertion sort --- c/insertion_sort.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 c/insertion_sort.c diff --git a/c/insertion_sort.c b/c/insertion_sort.c new file mode 100644 index 000000000..2cb168273 --- /dev/null +++ b/c/insertion_sort.c @@ -0,0 +1,6 @@ + +#include +int main(){ + printf("Hello world"); + return 0; +} \ No newline at end of file From ae1dfe90b2b993ea6ca08713e35567c65254eb46 Mon Sep 17 00:00:00 2001 From: sajalgupta Date: Fri, 7 Oct 2022 11:28:58 +0530 Subject: [PATCH 2/2] Insertion sort is completed in c --- c/insertion_sort.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/c/insertion_sort.c b/c/insertion_sort.c index 2cb168273..1091a42bc 100644 --- a/c/insertion_sort.c +++ b/c/insertion_sort.c @@ -1,6 +1,41 @@ +#include + void insertion_sort(int arr[], int n) + { + int i, key, j; + for (i = 1; i < n; i++) + { + key = arr[i]; + j = i - 1; + + + while (j >= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + } +int main() +{ + int n , j; + printf("Enter the count of element:"); + scanf("%d",&n); + int arr[n]; + printf("Enter the elements in the array:"); + for(int i=0;i -int main(){ - printf("Hello world"); - return 0; } \ No newline at end of file