From f76f3b6488c632f4c9d69d358daf9cbf902c800d Mon Sep 17 00:00:00 2001 From: Mark Groves Date: Tue, 2 Oct 2018 12:30:52 -0400 Subject: [PATCH] Added bubble sort method --- Sorting algorithms/BubbleSort.java | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Sorting algorithms/BubbleSort.java diff --git a/Sorting algorithms/BubbleSort.java b/Sorting algorithms/BubbleSort.java new file mode 100644 index 0000000..f5ee29f --- /dev/null +++ b/Sorting algorithms/BubbleSort.java @@ -0,0 +1,32 @@ +public class BubbleSort { + + void bubbleSort(int arr[]){ + for (int i = 0; i < arr.length-1; i++) + for (int j = 0; j < arr.length-i-1; j++) + if (arr[j] > arr[j+1]){ + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + + // Function to print elements + void printArray(int arr[]){ + for (int i=0; i