From 33f249c4d1ad709ef2ac7be1fabc9f25a892aa54 Mon Sep 17 00:00:00 2001 From: Nishant Sharma <42864292+goldenryu2000@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:16:01 +0530 Subject: [PATCH] Added Programs for Merge and Bubble Sort. Hope you like these Two Array Sorting Techniques. --- BubbleSort.java | 51 ++++++++++++++++++++++++++ MergeSort.java | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 BubbleSort.java create mode 100644 MergeSort.java diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..bd651cd --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,51 @@ +public class BubbleSort { + + public static void bubbleSort(int[] arr) + { + int n = arr.length; + int flag = 0; + for(int i=0;iarr[j+1]) + { + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + flag=1; + } + } + if(flag==0) break; //This exits the loop if the swap statement in inner j loop doesn't execute, it means the array is sorted. + } + } + + static void printArray(int arr[]) + { + int n = arr.length; + + for(int i=0; i