diff --git a/Sorting/Insertion Sort/insertionSort.c b/Sorting/Insertion Sort/insertionSort.c new file mode 100644 index 0000000..e99a21c --- /dev/null +++ b/Sorting/Insertion Sort/insertionSort.c @@ -0,0 +1,55 @@ +#include +#include + +void insertionSort(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; + } +} + +void input(int *arr, int n){ + printf("Elements: "); + for (int i=0; i