From 6398dfd0369c42da9db702fb84298722e6991da3 Mon Sep 17 00:00:00 2001 From: Madhura Date: Sun, 2 Oct 2022 16:46:53 +0530 Subject: [PATCH 1/5] 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/5] 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/5] 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 From 6e296590075cf0c176d9c83767da9d436fbe9573 Mon Sep 17 00:00:00 2001 From: Madhura Date: Sun, 2 Oct 2022 17:01:36 +0530 Subject: [PATCH 4/5] add merge sort in java --- java/MergeSort.java | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 java/MergeSort.java diff --git a/java/MergeSort.java b/java/MergeSort.java new file mode 100644 index 0000000..8992392 --- /dev/null +++ b/java/MergeSort.java @@ -0,0 +1,48 @@ + +import java.util.Arrays; + +public class MergeSort { + + public static int[] merge(int[] array1, int[] array2){ + int[] combined=new int[array1.length+ array2.length]; + int index=0; + int i=0; + int j=0; + + while (i< array1.length && j< array2.length){ + if (array1[i] Date: Sun, 2 Oct 2022 17:03:04 +0530 Subject: [PATCH 5/5] add quick sort in java --- java/QuickSort.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 java/QuickSort.java diff --git a/java/QuickSort.java b/java/QuickSort.java new file mode 100644 index 0000000..50d02c9 --- /dev/null +++ b/java/QuickSort.java @@ -0,0 +1,43 @@ + +import java.util.Arrays; + +public class QuickSort { + private static void swap(int[] array, int firstIndex, int secondIndex){ + int temp=array[firstIndex]; + array[firstIndex]=array[secondIndex]; + array[secondIndex]=temp; + } + + private static int pivot(int[] array, int pivotIndex, int endIndex){ + int swapIndex=pivotIndex; + for (int i = pivotIndex; i <=endIndex ; i++) { + if (array[i]