From 6398dfd0369c42da9db702fb84298722e6991da3 Mon Sep 17 00:00:00 2001 From: Madhura Date: Sun, 2 Oct 2022 16:46:53 +0530 Subject: [PATCH 1/3] add selection sort in java --- java/SelectionSort.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 java/SelectionSort.java diff --git a/java/SelectionSort.java b/java/SelectionSort.java new file mode 100644 index 0000000..baedddd --- /dev/null +++ b/java/SelectionSort.java @@ -0,0 +1,18 @@ + +public class SelectionSort { + public static void selectionSort(int[] array) { + for (int i = 0; i < array.length; i++) { + int minIndex=i; + for (int j = i+1; j < array.length; j++) { + if (array[j] Date: Sun, 2 Oct 2022 16:49:25 +0530 Subject: [PATCH 2/3] add insertion sort in java --- java/Insertion_Sort.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 java/Insertion_Sort.java diff --git a/java/Insertion_Sort.java b/java/Insertion_Sort.java new file mode 100644 index 0000000..911545c --- /dev/null +++ b/java/Insertion_Sort.java @@ -0,0 +1,13 @@ +public class InsertionSort { + public static void insertionSort(int[] array) { + for (int i = 1; i < array.length; i++) { + int temp = array[i]; + int j =i-1; + while (j>-1 && temp Date: Sun, 2 Oct 2022 16:59:04 +0530 Subject: [PATCH 3/3] add bubble sort in java --- java/Bubble_Sort.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 java/Bubble_Sort.java diff --git a/java/Bubble_Sort.java b/java/Bubble_Sort.java new file mode 100644 index 0000000..8c94af2 --- /dev/null +++ b/java/Bubble_Sort.java @@ -0,0 +1,13 @@ +public class BubbleSort { + public static void bubbleSort(int[] array){ + for (int i = array.length-1; i >0; i--) { + for (int j = 0; j < i; j++) { + if (array[j]>array[j+1]){ + int temp = array[j]; + array[j]=array[j+1]; + array[j+1]=temp; + } + } + } + } +} \ No newline at end of file