From 3a3382d8c7283858d14f4701a0db87285f6555cc Mon Sep 17 00:00:00 2001 From: Prachie Goje <71593659+prachie6157@users.noreply.github.com> Date: Sat, 30 Oct 2021 22:20:44 +0530 Subject: [PATCH] Create Bubble_Sort.java --- Sorting/Bubble Sort/Bubble_Sort.java | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Sorting/Bubble Sort/Bubble_Sort.java diff --git a/Sorting/Bubble Sort/Bubble_Sort.java b/Sorting/Bubble Sort/Bubble_Sort.java new file mode 100644 index 0000000..a21ef07 --- /dev/null +++ b/Sorting/Bubble Sort/Bubble_Sort.java @@ -0,0 +1,39 @@ +public class Bubble { + static void print (int a[]) //function to print array elements + { + int n = a.length; + int i; + for (i = 0; i < n; i++) + { + System.out.print(a[i] + " "); + } + } + static void bubbleSort (int a[]) // function to implement bubble sort + { + int n = a.length; + int i, j, temp; + for (i = 0; i < n; i++) + { + for (j = i + 1; j < n; j++) + { + if (a[j] < a[i]) + { + temp = a[i]; + a[i] = a[j]; + a[j] = temp; + } + } + } + } + public static void main(String[] args) { + int a[] = {35, 10, 31, 11, 26}; + Bubble b1 = new Bubble(); + System.out.println("Before sorting array elements are - "); + b1.print(a); + b1.bubbleSort(a); + System.out.println(); + System.out.println("After sorting array elements are - "); + b1.print(a); + +} +}