From 46f7b0178b1934e08360799a64b1739cd521082f Mon Sep 17 00:00:00 2001 From: Devansh80 Date: Thu, 28 Oct 2021 14:18:24 +0530 Subject: [PATCH] Implemeted InsertionSort in Java --- java/InsertionSort.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 java/InsertionSort.java diff --git a/java/InsertionSort.java b/java/InsertionSort.java new file mode 100644 index 0000000..00e7e91 --- /dev/null +++ b/java/InsertionSort.java @@ -0,0 +1,29 @@ +//Java Program for insertion sort +class InsertionSort +{ + /*sorting fuction*/ + void sort(int arr[]) + { + int len = arr.length; + for(int i = 1; i= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + } + +public static void main(String args[]) +{ + int arr[] = {12,11,13,5,6}; + + InsertionSort obj = new InsertionSort(); + obj.sort(arr); +} +} \ No newline at end of file