From bee1ba37d89f922e7744178354f3e1588f435544 Mon Sep 17 00:00:00 2001 From: SETHJI01 Date: Thu, 1 Oct 2020 23:10:29 +0530 Subject: [PATCH] Added more sorting algorithms --- data_structures/sortings/BubbleSort.java | 27 +++++++++++++++++++++ data_structures/sortings/SelectionSort.java | 27 +++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 data_structures/sortings/BubbleSort.java create mode 100644 data_structures/sortings/SelectionSort.java diff --git a/data_structures/sortings/BubbleSort.java b/data_structures/sortings/BubbleSort.java new file mode 100644 index 0000000..53f829a --- /dev/null +++ b/data_structures/sortings/BubbleSort.java @@ -0,0 +1,27 @@ +class BubbleSort { + void bubbleSort(int arr[]) { + int n = arr.length; + for (int i = 0; i < n-1; i++){ + for (int j = 0; j < n-i-1; j++){ + if (arr[j] > arr[j+1]){ + int temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + } + } + void printArray(int arr[]) { + int n = arr.length; + for (int i=0; i