diff --git a/c/insertion_sort.c b/c/insertion_sort.c new file mode 100644 index 000000000..1091a42bc --- /dev/null +++ b/c/insertion_sort.c @@ -0,0 +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