From 8f2a6b5f91956264fdf0973514937eaa01f181d5 Mon Sep 17 00:00:00 2001 From: pawan kumar Date: Tue, 2 Oct 2018 20:40:43 +0530 Subject: [PATCH] add insertion sort closes https://github.com/NITSkmOS/Algorithms/issues/63 --- insertion_sort/java/insertion_sort.java | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 insertion_sort/java/insertion_sort.java diff --git a/insertion_sort/java/insertion_sort.java b/insertion_sort/java/insertion_sort.java new file mode 100644 index 00000000..ab7fa5d3 --- /dev/null +++ b/insertion_sort/java/insertion_sort.java @@ -0,0 +1,43 @@ +// Java program for implementation of Insertion Sort +class InsertionSort +{ + /*Function to sort array using insertion sort*/ + void sort(int arr[]) + { + int n = arr.length; + for (int i=1; i=0 && arr[j] > key) + { + arr[j+1] = arr[j]; + j = j-1; + } + arr[j+1] = key; + } + } + + /* A utility function to print array of size n*/ + static void printArray(int arr[]) + { + int n = arr.length; + for (int i=0; i