diff --git a/Insertionsort.java b/Insertionsort.java new file mode 100644 index 0000000..7ca1817 --- /dev/null +++ b/Insertionsort.java @@ -0,0 +1,34 @@ +import java.util.Arrays; +import java.util.Scanner; + +public class InsertionSort{ + public static void sort(int arr[]) + { + int n = arr.length; + for (int i = 1; i < n; ++i) { + int key = arr[i]; + int j = i - 1; + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int n; + System.out.print("Enter Size of Array:"); + n = sc.nextInt(); + int arr[] = new int[n]; + System.out.print("Enter Array:"); + for(int i=0;i