From 1fab81f25ac9fe9e454397f1b65f9f07606ecdf0 Mon Sep 17 00:00:00 2001 From: Brian Hopper Date: Tue, 5 Oct 2021 12:47:41 -0700 Subject: [PATCH] Create BubbleSort.java Simple bubble sort of an integer array --- BubbleSort.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 BubbleSort.java diff --git a/BubbleSort.java b/BubbleSort.java new file mode 100644 index 0000000..9ba9c71 --- /dev/null +++ b/BubbleSort.java @@ -0,0 +1,16 @@ +public class BubbleSortExample { + static void bubbleSort(int[] arr) { + int n = arr.length; + int temp = 0; + for(int i=0; i < n; i++){ + for(int j=1; j < (n-i); j++){ + if(arr[j-1] > arr[j]){ + temp = arr[j-1]; + arr[j-1] = arr[j]; + arr[j] = temp; + } + + } + } + + }