From c784762e4df9021ac5196d5a359c5657ae99640a Mon Sep 17 00:00:00 2001 From: Richard Datko Date: Sun, 27 Sep 2026 08:27:25 -0700 Subject: [PATCH] Add bubble sort algorithm --- bubble-sort/BubbleSort.java | 47 +++++++++++++++++++++++++++++++++++++ bubble-sort/README.md | 16 +++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 bubble-sort/BubbleSort.java create mode 100644 bubble-sort/README.md diff --git a/bubble-sort/BubbleSort.java b/bubble-sort/BubbleSort.java new file mode 100644 index 0000000..5c81f18 --- /dev/null +++ b/bubble-sort/BubbleSort.java @@ -0,0 +1,47 @@ +/* + * @(#)BubbleSort.java 1.0.0 26/09/27 + * + * Bubble Sort implementation for ascending integer arrays. + * + * Built using Vim + * OpenJDK Runtime Environment 21.0.12 + * + */ + + +public class BubbleSort{ + + public static void main(String[]args){ + int arr[] = {1,56,38,3, 0, 16, 74}; + int i; + int j; + int k; + int l; + boolean flag; + k = 0; + l = 0; + + for(i = 0; i < arr.length-1;i++){ + flag = true; + for(j = 0; j < arr.length-1;j++){ + if(arr[j]> arr[j+1]){ + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + k++; + flag = false; + } + l++; + + } + if(flag){ + break; + } + } + + for(i = 0; i